title: PHP Session variable lost after refresh / redirect
body: <p>I am making login page and everything works fine, but while refreshing secure page or redirecting to another page variable disappears.</p>
  <p><strong>Login:</strong></p>
  <pre><code>&lt;?php session_start(); 
  
  //connection to database and other stuff
  
  if ($user == $dbuser &amp;&amp; $pass == $dbpass) {
  
      $_SESSION['user'] = $user;
      $_SESSION['authenticated'] = &quot;yes&quot;;
      $suser = $_SESSION['user']; //just to test if session works
  
  }
  
  ?&gt;
  </code></pre>
  <p><strong>Secure page:</strong> <br></p>
  <pre><code>&lt;?php session_start(); ?&gt;
  
  //small amount of html here
  
  &lt;?php
      $suser = $_SESSION['user'];
      $sauth = $_SESSION['authenticated'];
  
      if ($sauth != 'yes') { //not completed yet (needs user name check)
          echo &quot;&lt;a href='./'&gt;Log in&lt;/a&gt; first!&quot;;
          require ('./login.php');
          die;
      } else {
      //not so important code here
      }
  ?&gt;
  
  //rest of html here
  </code></pre>
  <p>I didn't notice any mistakes and error log file is clean so it must be something else. Session works fine after redirecting to secure page but as I said earlier refresh of page or another redirect clears session variables.</p>
  <p>Page: <a href="http://nano.filiparag.com/admin/" rel="nofollow noreferrer">http://nano.filiparag.com/admin/</a>
  If you want to test it just ask for username and password</p>
  <p><strong>Note:</strong><br />
  Now I tried doing this with <code>setcookie()</code> and it didn't work again</p>
  <hr />
  <h3>Solved</h3>
  <p>The problem was in logout button. I made separate PHP file for it and now everything works fine.</p>