title: PHP automatic logout without having to refresh the page
body: <p>I am writing a project in PHP, JavaScript and HTML. I have successfully done the automatic logout when the user is idle for 1 minute. But the problem comes in that I have to refresh the page for it to be executed and log me out.</p>
  
  <p>Can somebody help me so that immediately 1 minute is over and the user is idle, the code will be executed and it will take me to the login page without me refreshing it?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>// check to see if $_SESSION['timeout'] is set
  if(isset($_SESSION['timeout']) ) {
  $session_life = time() - $_SESSION['timeout'];
  if($session_life &gt; $inactive)
      {  
  
  
   echo"&lt;script type='text/javascript'&gt; 
  window.alert('Your Session got Expired');
  &lt;/script&gt;";
  header("Location: logout.php");
  }
  }
  
  $_SESSION['timeout'] = time();
  //Continuation of other codes
  </code></pre>