title: Automatic refresh page and destroy session in php after 30 seconds of page inactivity, without any user interaction?
body: <p>This code works perfectly when user press refresh after 30 sec of page inactivity, but i need some code to automatic destroy sassion and refresh page after 30 seconds of inactivity.</p>
  
  <pre><code>  &lt;?php
      $inactive = 30;
      ini_set('session.gc_maxlifetime', $inactive);
      session_start();
  
      if (isset($_SESSION['testing']) &amp;&amp; time() - $_SESSION['testing'] &gt; $inactive) {
          session_unset();     // unset $_SESSION variable for this page
          session_destroy();   // destroy session data
       echo "&lt;br&gt;&lt;br&gt;Sorry, you can't go any further!!!";
       echo "&lt;br&gt;Please log in.";
       echo "&lt;br/&gt;&lt;a href='index.php'&gt;Go back to login page&lt;/a&gt;";
      }else{
      //Here is some code to do when the session is still active
      }
  
      $_SESSION['testing'] = time();
      ?&gt;
  </code></pre>