title: php not setting infinite cookie
body: <p>Ok, so now I have this code in my login form handler <code>.php</code> file:</p>
  
  <pre><code>&lt;?php
      $username = "root";
      $password = "root";
      $hostname = "localhost";
      $db = "agendadb";
      $db = new mysqli($hostname, $username, $password, $db);
    $res = $db-&gt;query("SELECT userId FROM tblUsers WHERE username='".$_POST['username']."' AND password='".md5($_POST['password'])."'");
    if($res){
      if($row =  $res-&gt;fetch_assoc()){
        setcookie('userId', strval($row['userId']), 2147483647);
        $_COOKIE['userId']= $row['userId'];
        echo 1;
      }else{
        echo -2;
      }
    }else{
      echo -1;
    }
  ?&gt;
  </code></pre>
  
  <p>Somewhy, the cookie <code>userId</code> is not being set, and I can't figure out why. The script is working because it echoes the result correctly, but the cookie is not being set and no errors are thrown.</p>
  
  <p>In the begining of my index page I have the following code to check if the cookie has been set</p>
  
  <pre><code>&lt;?php
  echo '&lt;script&gt;';
  
  if(!isset($_COOKIE['userId'])){
    echo 'console.log(" isset");';
  }
  if(empty($_COOKIE['userId'])){
    echo 'console.log(" empty");';
  }
  if($_COOKIE['userId']==""){
    echo 'console.log(" ==");';
  }
  echo '&lt;/script&gt;';
  ?&gt;
  </code></pre>
  
  <p>and after loging in my console in <code>index.php</code> always shows <code>isset empty ==</code></p>
  
  <p>Also, I tried using <code>ob_start();</code>  and <code>ob_end_flush();</code> in the login handler <code>.php</code> file, but did not work either. </p>
  
  <p>Any help would be appreciated.</p>