title: PHP Cookie Login System
body: <p>I am having a problem with the cookies finding the cookies stored from my login page.Here is my login page code:</p>
  
  <pre><code>&lt;?php 
  // Connects to your Database 
  include("dbconnect.php");
  mysql_select_db("maxgee_close2");
  //Checks if there is a login cookie
  
  if(isset($_COOKIE['ID_my_site']))
   //if there is, it logs you in and directes you to the members page
  { 
      $username = $_COOKIE['ID_my_site']; 
      $password = $_COOKIE['Key_my_site'];
      $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
      while($info = mysql_fetch_array( $check )) 
      {
          if ($password != $info['password'])
          {
          }
          else
          {
              header("Location: members.php");
          }
      }
  }
  //if the login form is submitted 
  if (isset($_POST['submit'])) { // if form has been submitted
   // makes sure they filled it in
      if(!$_POST['username'] | !$_POST['password']) {
          die('You did not fill in a required field.');
      }
      // checks it against the database
  
      if (!get_magic_quotes_gpc()) {
          $_POST['email'] = addslashes($_POST['email']);
      }
      $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  
      //Gives error if user dosen't exist
      $check2 = mysql_num_rows($check);
      if ($check2 == 0) {
          die('That user does not exist in our database. &lt;a href=add.php&gt;Click Here to Register&lt;/a&gt;');
      }
      while($info = mysql_fetch_array( $check ))  
      {
          $_POST['password'] = stripslashes($_POST['password']);
  
          $info['password'] = stripslashes($info['password']);
  
          $_POST['password'] = md5($_POST['password']);
  
          //gives error if the password is wrong
  
          if ($_POST['password'] != $info['password']) {
              die('Incorrect password, please try again.');
          }
          else 
          { 
              // if login is ok then we add a cookie 
             setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */
  
  
            //then redirect them to the members area and the line with the error
            header("Location: members.php");
          }
      } 
    }
    else
    { 
      // if they are not logged in
       ?&gt;
       &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post"&gt;
       &lt;h1&gt;Login&lt;/h1&gt;
       Username:
      &lt;input type="text" name="username" maxlength="40"&gt; 
      Password:
      &lt;input type="password" name="password" maxlength="50"&gt; 
      &lt;input type="submit" name="submit" value="Login"&gt;
      &lt;/form&gt; 
  &lt;?php 
   } 
   include("topsite.php");
  ?&gt; 
  </code></pre>
  
  <p>Members Page:
  Here is the page that cant find the cookies I have found the cookies saved in my browser this page just cant find them:</p>
  
  <pre><code>&lt;?php 
  include("dbconnect.php");
  mysql_select_db("maxgee_close2");
  
  //checks cookies to make sure they are logged in 
  
  if(isset($_COOKIE['maxgee.me'])) 
  
   { 
  
  $username = $_COOKIE['maxgee.me']; 
  
  $password = $_COOKIE['maxgee.me']; 
  
      $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
  
  while($info = mysql_fetch_array( $check ))   
  
      { 
  
  
  
    //if the cookie has the wrong password, they are taken to the login page 
  
      if ($password != $info['password']) 
  
          {           header("Location: login_test.php"); 
  
          } 
  
  
  
      //otherwise they are shown the admin area    
  
  else 
  
          { 
  
           echo "Admin Area&lt;p&gt;"; 
  
     echo "Your Content&lt;p&gt;"; 
  
     echo "&lt;a href=logout.php&gt;Logout&lt;/a&gt;"; 
  
          } 
  
      } 
  
      } 
  
      else 
  
  
  
     //if the cookie does not exist, they are taken to the login screen 
  
    {          
  
     header("Location: login_test.php"); 
  
     } 
  
     ?&gt; 
  </code></pre>