title: PHP/Session/Caching - Unable to remove logged in user from index.php page after processing logout.php?
body: <p>I have a three PHP scripts (logout.php, index.php, session.php) that I use in a larger application.  I incorporated session.php (to serve as a mechanism to control preserving page view for pressing back button on the browser).</p>
  
  <p>I am trying to make the logout.php clear cache and the logged in user info on the webpage but no matter what I do I can not seem to logout. That is, the user still remains on my page as logged in.</p>
  
  <p>How can I logout to ensure that the user does not appear as logged in on my index.php page?</p>
  
  <p><strong>session.php</strong></p>
  
  <pre><code>&lt;? 
    session_cache_limiter('public');
    session_start();
  ?&gt;
  </code></pre>
  
  <p><strong>logout.php</strong></p>
  
  <pre><code>&lt;?php
      session_start();
      $_SESSION['expire'] = "&lt;META HTTP-EQUIV=\"EXPIRES\" CONTENT=\"Mon, 02 May 2015 21:00:00 GMT\"&gt;";
      header('Location: index.php');                                             
  ?&gt;
  </code></pre>
  
  <p><strong>beginning of index.php script</strong></p>
  
  <pre><code>&lt;?php   
      session_start(); 
      if (isset($_SESSION['expire']))
      {              
          echo $_SESSION['expire'];
          session_unset();
          session_destroy();
          unset($_SESSION);
      } 
  ?&gt;
  </code></pre>
  
  <p>Error Log shows the following each time I try to logout.</p>
  
  <p>PHP Notice:  A session had already been started - ignoring session_start() in index.php on line 6   &lt;-- this is referring to where I have session_start() in my if block in my local code.</p>
  
  <p><strong>EDIT - Modified index.php</strong></p>
  
  <pre><code>&lt;?php
      if (isset($_SESSION['expire']))
      {      
          session_start();        
          echo $_SESSION['expire'];
          session_destroy();
      } 
      else
      {
          require_once('session.php');
      }
  ?&gt;
  </code></pre>
  
  <p><strong>Latest index.php script</strong></p>
  
  <pre><code>&lt;?php
      if (session_status() === PHP_SESSION_NONE)
      {
          require_once('session.php');
      }
      else
      {
          session_start();  
          if (isset($_SESSION['expire']))
          { 
              $expire = $_SESSION['expire'];
              session_destroy();
              echo $expire;
          }
      }
  ?&gt;
  </code></pre>