title: Setting a cookie in an AJAX request?
body: <p>I'm validating a login form with jQuery AJAX call to PHP. In php, I create a session and if they checked the 'remember me' checkbox, I want to create a cookie. Here's the php code:</p>
  
  <pre><code>&lt;?php
  
  include '../includes/connection.php';
  date_default_timezone_set('GMT');
  
  $name = $_POST['username'];
  $pass = $_POST['password'];
  
  
  $query = mysql_query("SELECT id, username, password FROM users WHERE username = '$name' LIMIT 1");
  
  if(mysql_num_rows($query) == 0) {
   echo 'error';
   exit;
  }
  
  while($row = mysql_fetch_array($query)) {
  
   if($row['username'] == $name &amp;&amp; $row['password'] == $pass) {
  
    session_start();
    $_SESSION['username'] = $row['username'];
    $_SESSION['usrID'] = $row['id'];
    echo 'success';
  
  
    if($_POST['remember']) {
     setcookie('username', $row['username'], $exp);
     setcookie('password', $row['password'], $exp);
     setcookie('usrID', $row['id'], $exp);
    }
  
   } else {
    echo 'error';
    exit;
   }
  
  
  
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>The session is set successfully, however the cookie is not set at all. I've tried setting all the values (domain, path, etc.) but that didn't change anything. Is there anything obvious I'm missing?</p>