title: Automatically log out the user if he is not active for a certain period of time
body: <p>I want a user to be automatically logged out after 30 minutes if he hasn't been active.  </p>
  
  <p>I've tried the following code :<br>
  Index.php :  </p>
  
  <pre><code>&lt;?  
  if ((time() - $_SESSION['last_activity']) &gt; 1800) // 30* 60 = 1800
  {  
     header("Location: logout.php");  
  }  
  ?&gt;
  </code></pre>
  
  <p>login.php:  </p>
  
  <pre><code>&lt;?  
          $_SESSION['unm'] = $row['u_unm'];
          $_SESSION['uid'] = $row['u_pwd'];
          $_SESSION['status'] = true;
          $_SESSION['last_activity'] = time();  
  ?&gt;  
  </code></pre>
  
  <p>My problem is I don't understand how this code is keeping track of user activity?  </p>
  
  <p>The problem I am facing is determining whether the user is active or not. But I want the user only to be logged out if he is not doing anything. </p>
  
  <p>Can anybody tell me how to keep track of that?  Thanks.</p>