title: Session disappear after page refresh
body: <p>This is the first time that I'm using sessions on PHP.
  Getting some info from StackOverflow and other websites I'm into to build my first PHP Login but I'm getting a problem and don't know how to resolve it.</p>
  
  <p>Basically at the moment that I set a session, after the page refresh, this session disappear. Is not supposed to remain for an amount of time? (that can be set with <code>set_cookie_params</code> etc, but this is another topic)</p>
  
  <p>I have at the beginning of my page (global) this code:</p>
  
  <pre><code>ini_set('session.cookie_httponly', 1);
  ini_set('session.entropy_file', '/dev/urandom');
  ini_set('session.hash_function', 'whirlpool');
  ini_set('session.use_only_cookies', 1);
  ini_set('session.cookie_secure', 1);
  
  session_name("RANDOMID");
  session_start();
  
  if (isset($_SESSION['uid']))
  {
      if ($_SESSION['ipremote'] !== getUserIP() &amp;&amp; $_SESSION['useragent'] !== getUserAgent())
      {
          session_unset();
          session_destroy();
  
          session_regenerate_id(true);
      }
  }
  else
  {
      session_regenerate_id(true);
  
      $_SESSION['ipremote'] = getUserIP();
      $_SESSION['useragent'] = getUserAgent();
  }
  </code></pre>
  
  <p>then in my <strong>login.php</strong> file, when the user insert the right infos:</p>
  
  <pre><code>$_SESSION['uid'] = 3;
  
  header("Location: index.php");
  exit;
  </code></pre>
  
  <p>The problem that after the redirect the uid session disappear: I put at the end of the <strong>index.php</strong> page a <code>var_dump</code> of the <code>$_SESSION</code> variable, and I see just the IP and user-agent that is set everytime in the <code>else</code> condition.</p>
  
  <p><strong>EDIT</strong>: I tried to replace all the content of the session initialization with just <code>session_start();</code> and it works, I don't understand why this secure session initialization it doesn't working and making the session disappear.</p>