title: At what point is session data available?
body: <p>I have the following so far opening a session (php),</p>
  
  <pre><code>session_start() ;
  
  foreach($_SESSION as $key =&gt; $value){
      $alert .= '&lt;br/&gt;' . '['.$key.']='.$value ;
  }
  
  $alert .= '&lt;br/&gt;$_SERVER[MY_SERVER...]='.$_SERVER['MY_SERVER_GENERATED'] ;
  
  if($_SESSION['MY_SERVER_GENERATED'] !== true ||
      $_SERVER['REMOTE_ADDR'] !== $_SESSION['PREV_REMOTEADDR'] ||
      $_SERVER['HTTP_USER_AGENT'] !== $_SESSION['PREV_USERAGENT']){
          $alert .= 'session destroyed' ;
          session_destroy() ;
  }
  
  if(isset($_SESSION['CREATED']) &amp;&amp; (strtotime('now') - $_SESSION['CREATED']) &gt; 300){//Delete expired sessions - seconds
      $alert .= '&lt;div class="error_box"&gt;Your session has expired!&lt;/div&gt;' ;
      $_SESSION = array() ;
  }
  
  session_regenerate_id();
  $_SESSION['CREATED'] = strtotime('now') ;
  $_SESSION['MY_SERVER_GENERATED'] = true ;
  $_SESSION['PREV_USERAGENT'] = $_SERVER['HTTP_USER_AGENT'] ;
  $_SESSION['PREV_REMOTEADDR'] = $_SERVER['REMOTE_ADDR'] ;
  
  echo $alert ;
  </code></pre>
  
  <p>The problem is the session is being destroyed everytime. $_SESSION is simply empty. At what point is it available to run checks like above?</p>
  
  <p>Oops forgot to specifiy that I have verified the session is holding data but not until the page has been started. So the session is being destroyed because the $_SESSION data is all null and so the conditions are evaluating to false. As an example $alert does not register as having anything stored in it.</p>