title: display a message before session timeout triggers
body: <p>I have a php webpage that logs users out after 10 seconds of inactivity. After 10 seconds, I need to hit the refresh button before it redirects to the main index.php page. How do I make a popup box displaying "You are logged out due to inactivity" and after that it redirects to index.php without refreshing?
  P/S: I'm a student learning the basics so I don't know much.</p>
  
  <pre><code>session_start();
  
  $timeout = 10;
  // Check if the timeout field exists.
  if(isset($_SESSION['timeout'])) {
  // See if the number of seconds since the last
  // visit is larger than the timeout period.
  $duration = time() - (int)$_SESSION['timeout'];
  if($duration &gt; $timeout) {
  // Destroy the session and restart it.
  session_destroy();
  session_start();
  }
  }
  
  So I tried something like this using alert.Why doesn't it work?
  &lt;?php
  //include ("popup.php");
  session_start();
  
  $timeout = 10;
  // Check if the timeout field exists.
  if(isset($_SESSION['timeout'])) {
  // See if the number of seconds since the last
  // visit is larger than the timeout period.
  $duration = time() - (int)$_SESSION['timeout'];
  if($duration &gt; $timeout) {
  echo"&lt;script type='javascript'&gt;alert('10 seconds over!');
  header("location:../../index.php");
  &lt;/script&gt;";
  
  }
  // Destroy the session and restart it.
  session_destroy();
  session_start();
  header("location:../../index.php");
  }
  
  
  // Update the timout field with the current time.
  $_SESSION['timeout'] = time();
  </code></pre>