Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php  
  2. session_start();
  3.  
  4. if(!isset($_SESSION['user_id']))
  5. {
  6.     /* Redirect If Not Logged In */
  7.     header("Location: Login.php");
  8.     exit; /* prevent other code from being executed*/
  9. } else {
  10.   /*we are going to start tracking a new session variable we will call timeout.
  11.    by comparing the session timeout plus 600 seconds to the current time,
  12.    we can force users to the logout page when they attempt to access the page, after 10 mins of inaction*/
  13.   if ($_SESSION['timeout'] + 10 * 60 < time()) {
  14.     /* session timed out */
  15.     header("Location: Logout.php");
  16.   } else {
  17.     /*if the user isn't timed out, update the session timeout variable to the current time.*/
  18.      $_SESSION['timeout'] = time();
  19.   }
  20. }
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement