title: session_destroy() after certain amount of time in PHP
body: <p>I am currently saving a session in my form page:</p>
  <blockquote>
  <p>$testingvalue = &quot;SESSION TEST&quot;;</p>
  <p>$_SESSION['testing'] = $testingvalue;</p>
  </blockquote>
  <p>On another page I am calling the session to use the value:</p>
  <pre><code>&lt;?php
  session_start(); // make sure there is a session
  
  echo $_SESSION['testing']; //prints SESSION TEST???
  ?&gt;
  </code></pre>
  <p>Now I want to use the</p>
  <blockquote>
  <p>session_destroy();</p>
  </blockquote>
  <p>to destroy the session. But what I would like to do is destroy the session after 2 hours have been passed.</p>
  <p>Any idea on how to do it and also where should I put it?</p>
  <p>I have something like this:</p>
  <pre><code> &lt;?php
  session_start();
  
  // 2 hours in seconds
  $inactive = 7200; 
  
  $session_life = time() - $_session['testing'];
  
  if($session_life &gt; $inactive)
  {  
   session_destroy(); 
  }
  
  $_session['testing']=time();
      
      echo $_SESSION['testing']; //prints NOTHING?
      ?&gt;
  </code></pre>
  <p>Will that work?</p>
  <p>If I am inactive for more than 2 hours this should be blank?:</p>
  <blockquote>
  <p>echo $_SESSION['testing'];</p>
  </blockquote>