title: PHP not setting cookies but does set sessions
body: <p>I have made a login that works for sessiosn but not cookies.. here is my login.php code</p>
  
  <pre><code>          &lt;?php 
  
  
  
      include 'functions.php';
      if(loggedin()){
          header("Location: index.php");
          exit();
      }
      if(isset($_POST['login'])){
  
          $username=$_POST['username']; 
          $password=$_POST['password'];
          if(isset($_POST['rememberme'])) {
            $rem=$_POST['rememberme'];
          } else { $rememberme=""; }
  
          if($username&amp;&amp;$password){
          $login = mysql_query("SELECT * FROM users WHERE username='$username'");
  
          while($row = mysql_fetch_assoc($login)){
              $db_password = $row['password'];
              if($password == $db_password){
                  $loginok= TRUE;
              }
              else{
                  $loginok= FALSE;
              }
  
              if($loginok==TRUE)
              {
                  if($rememberme=="on"){
                      setcookie("username",$username, time() + 7200);
                  }else if ($rememberme==""){
                  $_SESSION['username'] = $username;}
                  header("Location: index.php"); 
                  exit();
              }
              else
                  die("Incorrect Username/Password");
          }
          }
          else 
          die("Please enter a username and password");        
      }
  </code></pre>
  
  <p>and my functions.php</p>
  
  <pre><code>       &lt;?php
  
        session_start();
  
  
      $host = "localhost";
      $user = "root";
      $pass = "";
      $db = "loginphp";
  
  
       mysql_connect($host, $user, $pass) or die("Couldn't connect");
       mysql_select_db($db);
  
      function loggedin()
      {
          if(isset($_SESSION['username'])||(isset($_COOKIE['username'])))
          {
          $loggedin = TRUE;
          return $loggedin;   
          }
      }
  </code></pre>
  
  <p>but when I close the broswer the cookie does not save and it acts as if i've logged out completely.
  sessions work fine..</p>
  
  <p>here is my logout.php as well</p>
  
  <pre><code>session_start();
  session_destroy();
  
  setcookie("username","",time() - 7200);
  
  header("Location: login.php");
  </code></pre>