title: Why are my cookies not setting?
body: <p>I have the following PHP function:</p>
  
  <pre><code>function validateUser($username){
      session_regenerate_id (); 
      $_SESSION['valid'] = 1;
      $_SESSION['username'] = $username;
      setcookie('username2',$username,time()+60*60*24*365);
      header("Location: ../new.php");
  }
  </code></pre>
  
  <p>And then I fetch the cookie:</p>
  
  <p><code>echo $_COOKIE['username2']; exit();</code></p>
  
  <p>(I only put <code>exit()</code> for debugging purposes)</p>
  
  <p>Only problem, it's coming out blank. Any ideas?</p>
  
  <p><b>UPDATE:</b>
  This is how the function is called:</p>
  
  <pre><code>    if(mysql_num_rows($queryreg) != 0){
      $row = mysql_fetch_array($queryreg,MYSQL_ASSOC);
      $hash = hash('sha256', $row['salt'] . hash('sha256', $password));
      if($hash == $row['password']) {
          if($row['confirm'] == 1){
              if(isset($remember)){
                  setcookie('username',$username,time()+60*60*24*365);
                  setcookie('password',$password,time()+60*60*24*365);
              } else {
                  setcookie('username','',time()-3600);
                  setcookie('password','',time()-3600);
              }
              validateUser($username);
  </code></pre>
  
  <p>I didn't include all the <code>if()</code> statements to save some space.</p>