title: $_SESSION['var'] does not save the variable until the second login
body: <p>I try to login to my site but the $_SESSION[] variable is not saving the data. I can't login until I try a second time. It only happens when I login for the first time in any computer. After that When I login again in the same computer it only takes one try. Erasing the cookies makes have to login twice again.
  I check if the variable exists in page.php and if it does not it redirects me to index.php</p>
  
  <p>code in page.php to check if session login variable is empty  </p>
  
  <pre><code>&lt;?php
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  header('Content-Type: text/html; charset=UTF-8');
  session_start();
  ob_start();
  
  
  if(empty($_SESSION['login'])){
      echo '&lt;meta HTTP-EQUIV="REFRESH" content="0; url=index.php"&gt;';
  }
  </code></pre>
  
  <p>this is the code that I have (index.php):</p>
  
  <pre><code>&lt;?php
  session_start();
  ob_start();
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  include("conec.php");
  
  $message="";
  
  
      if(isset($_SESSION['login'])) {
          //echo '&lt;meta HTTP-EQUIV="REFRESH" content="0; url=page.php"&gt;';
      }
  
      $message="";
      if(isset($_POST['send'])) {
          $result = mysql_query("SELECT login FROM user WHERE login='" . $_POST["login"] . "' and password = '". $_POST["password"]."'");
          $row  = mysql_fetch_array($result);
          if(is_array($row)) {
              $_SESSION['login'] = $row[login];
              echo '&lt;meta HTTP-EQUIV="REFRESH" content="0; url=page.php"&gt;';
          } else {
              $message = "Invalid user or password!";
          }
  
      }
  
          &lt;form class="form-horizontal" role="form" name="" method="post"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-2" for="login"&gt;Login:&lt;/label&gt;
                  &lt;div class="col-sm-10"&gt;
                    &lt;input type="text" class="form-control" id="login" name="login"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-2" for="pwd"&gt;Password:&lt;/label&gt;
                  &lt;div class="col-sm-10"&gt; 
                    &lt;input type="password" class="form-control" id="password" name="password"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;button type="submit" name="send" id="send" class="btn btn-primary pull-right"&gt;Send&lt;/button&gt;&lt;br /&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>I have also tried</p>
  
  <pre><code>header("Location: page.php");
  header("Location: http://www.page.php");
  echo '&lt;meta HTTP-EQUIV="REFRESH" content="0; url=http://www.page.php"&gt;';
  </code></pre>
  
  <p>The only one that has been able to redirect me to other pages has been when I use either </p>
  
  <pre><code>echo '&lt;meta HTTP-EQUIV="REFRESH" content="0; url=http://www.page.php"&gt;';  
  </code></pre>
  
  <p>or</p>
  
  <pre><code>echo '&lt;meta HTTP-EQUIV="REFRESH" content="0; url=page.php"&gt;';  
  </code></pre>