title: Keep PHP session alive until an hour of "inactivity" has passed
body: <p>I have read several articles on this topic but still don't fully understand the relationship between the client-side session cookie, the server-side session file, and the way PHP "randomly" chooses to remove or keep a session during garbage collection.</p>
  
  <p>The behavior I am trying to ensure is:</p>
  
  <ul>
  <li>a user logs in, and the session begins </li>
  <li>if the user is inactive* for a period of 1 hour, the session is
  destroyed</li>
  </ul>
  
  <p>*this is critical for my site because the user may be spending an hour apparently "idle" on the same page, but in fact they are not idle. They may be composing a long written report, watching a video, etc.</p>
  
  <p>What I'm using so far is:</p>
  
  <pre><code>session_start();
  setcookie(session_name(),session_id(),time()+3600);
  </code></pre>
  
  <p>This code is executed on every page load.</p>
  
  <p>I also have an AJAX request firing every minute via a setInterval, which loads a PHP script containing the above code on pages where the user is apparently "idle".</p>
  
  <p>Will my approach ensure the behavior I require? Or am I missing something? Perhaps there is a cleaner way to ensure this behavior.</p>
  
  <p>Many thanks in advance.</p>