title: PHP sessions not saved properly
body: <p>I have a huge problem regarding sessions in php. I am pretty new to php so I probably made a mistake.</p>
  
  <p>The main problem is, that session variables aren't saved properly.
  I wrote a little login script with recaptcha an stuff:</p>
  
  <pre><code>&lt;?php 
      if (!isset($_SESSION['user_id'])) {
          echo "NOT SET";
  ?&gt;
      &lt;h1&gt;Authentifikation&lt;/h1&gt;
  &lt;?php
      if (isset($_POST['authentificate']) &amp;&amp; $_POST['authentificate'] == 'Bestätigen') {
          if(!isset($_POST['g-recaptcha-response']) || !isset($_POST['username']) || !isset($_POST['userpass'])) {
              MessageHandler('Bitte korrigiere deine Angaben.', 2);
              return;
          }
  
          $topl_curl = curl_init();
          curl_setopt($topl_curl, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
          curl_setopt($topl_curl, CURLOPT_HEADER, 0);
          curl_setopt($topl_curl, CURLOPT_POST, true);
          curl_setopt($topl_curl, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($topl_curl, CURLOPT_POSTFIELDS, http_build_query(array(
              'secret'    =&gt; $settings['CAPTCHA']['PRIVATE_KEY'],
              'response'  =&gt; $_POST['g-recaptcha-response'],
          )));
          curl_setopt($topl_curl, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($topl_curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11');
          $topl_data = curl_exec($topl_curl);
          $topl_info = curl_getinfo($topl_curl);
  
          if (!$topl_info['http_code'] == 200 ) {
              print_r($topl_info);
              echo 'RE-Captcha ERROR';
              return;
          }
          $jResponse = json_decode($topl_data, true);
          if ($jResponse['success']) {
              $result = $mysqli-&gt;query("SELECT id, login, cash, status FROM account.account WHERE login LIKE '".$mysqli-&gt;real_escape_string($_POST['username'])."' AND password = PASSWORD('".$mysqli-&gt;real_escape_string($_POST['userpass'])."') LIMIT 1");
              if ($result-&gt;num_rows &gt; 0) {
                  $info = $result-&gt;fetch_object();
                  if ($info-&gt;status == 'BLOCK' &amp;&amp; $settings['MODE'] != 'BEFORE_START') {
                      MessageHandler('Dieser Account ist gesperrt.', 3);
                      return;
                  }
                  $_SESSION['user_id'] = $info-&gt;id;
                  $_SESSION['user_name'] = $info-&gt;login;
                  $_SESSION['user_dr'] = $info-&gt;cash;
                  MessageHandler('Du wurdest erfolgreich eingeloggt.', 2);
  ?&gt;
  &lt;script&gt;
  setTimeout(function() {
          window.location.replace("/index.php?s=login");
  }, 3000);
  &lt;/script&gt;
  &lt;?php
              } else {
                  MessageHandler('Deine Login Daten sind fehlerhaft, bitte versuche es erneut.');
              }
              return;
          }
      }
  ?&gt;
  &lt;center&gt;&lt;p&gt;Bitte authentifizieren Sie sich indem Sie das Captcha ausfüllen.&lt;/p&gt;&lt;/center&gt;
  &lt;form method="POST" action="?s=login"&gt;
      &lt;center&gt;&lt;br&gt;&lt;div class="g-recaptcha" data-sitekey="&lt;?=$settings['CAPTCHA']['PUBLIC_KEY'] ?&gt;"&gt;&lt;/div&gt;
      &lt;input type="hidden" name="username" value="&lt;?=$_POST['username']?&gt;"&gt;
      &lt;input type="hidden" name="userpass" value="&lt;?=$_POST['userpass']?&gt;"&gt;
      &lt;br&gt;&lt;input type="submit" name="authentificate" value="Bestätigen"/&gt;&lt;/center&gt;
  &lt;/form&gt;
  &lt;?php
      }
      else {
      if (!isset($_SESSION['user_id'])) {
          echo "NOT SET";
      }
  ?&gt;
  &lt;?php
      }
  ?&gt;
  </code></pre>
  
  <p>I also display session infos to see what happens after executing the script:</p>
  
  <pre><code>session_id: aea6434a454efb40851d035612307b25
  array(3) { ["user_id"]=&gt; string(1) "1" ["user_name"]=&gt; string(5) "admin" ["user_dr"]=&gt; string(6) "887992" } uid:
  session.cookie_domain: 
  session file: /var/customers/tmp/censored//sess_aea6434a454efb40851d035612307b25 
  size: 59 
  </code></pre>
  
  <p>So obviously the settings are set, but after the javascript refreshing after 3 seconds, the following session infos appear:</p>
  
  <pre><code>session_id: aea6434a454efb40851d035612307b25
  array(0) { } uid:
  session.cookie_domain: 
  session file: /var/customers/tmp/censored//sess_aea6434a454efb40851d035612307b25 
  size: 0 
  </code></pre>
  
  <p>I searched a lot to fix this but every question here at stackoverflow which was answered did not help solving my problem.</p>
  
  <p>Do you have any suggestions what to try?
  The session_path is set correctly..</p>