title: Detect PHP session timeout
body: <p>I need to detect if PHP <code>session_start()</code> has timeOut to tell the user that the session has ended.</p>
  <p>I added an iFrame that checks session variables for validity. Every hour (JavaScript), the iFrame should check the session state. If it is still valid, it will check again in an hour. If the session values are no longer valid, I make sure to end the session correctly and refresh the <code>parent.frame</code> page which will now display to connect again.</p>
  <p>The problem is that the main page which contains the iFrame refreshes continuously and not every hour. Something is wrong.</p>
  <p>Here are the codes:</p>
  <pre><code>&lt;iframe src=&quot;logOutAutomatic.php&quot; id=&quot;iframeLogOutAutomatic&quot; name=&quot;iframeLogOutAutomatic&quot; style=&quot;position:absolute; width:0; height:0; border:0; display:none;visibility: hidden;&quot;&gt;&lt;/iframe&gt;
  </code></pre>
  <p><strong>logOutAutomatic.php</strong></p>
  <pre><code>&lt;?php session_start();
  if (!isset($_SESSION['loginID']) || !isset($_SESSION['pwdID'])) {
    session_unset();
    session_destroy();
    $javaNoSessionActive = '&lt;script type=&quot;text/javascript&quot;&gt;';
    $javaNoSessionActive .= 'window.parent.location.reload();';
    $javaNoSessionActive .= '&lt;/script&gt;';
    echo $javaNoSessionActive;
  }
  else {
    $javaSetTimer = '&lt;script type=&quot;text/javascript&quot;&gt;';
    $javaSetTimer .= 'setTimeout(function(){location.reload();}, 3600000);';
    $javaSetTimer .= '&lt;/script&gt;';
    echo $javaSetTimer;
  }
  ?&gt;
  </code></pre>