So I have a simple login + set cookie script. After checking to see if the supplied credentials are in the db, the script sets a cookie. After this, the script forwards the user to a password protected page.
I know the login + cookie placing script works fine. When I try the wrong credentials it fails like it should and when I enter the right credentials it sets a cookie (i can see it in my cookies on my browser).
The problem comes when I try to read the cookies back to make sure a user is credentialed for a certain page.
Here is my cookie-reading part of the script:
<?php
$user = $_COOKIE['user']; //gets the user from the cookies
$pass = $_COOKIE['pass']; //gets the pass from cookies
include("connect.php"); // connects to our database
$login = mysql_query("SELECT * FROM members WHERE username='$user' AND password='$pass'") or die(mysql_error()); //selects info from our table if the row has the same user and pass that our cookies do
if(!mysql_num_rows($login)) //if the username and pass are wrong
{
header("Location: index.php"); //redirects to our login page
die(); //stops the page from going any further
}
?>
And, for reference, this is the cookie placing part of the other script:
if($count==1){
setcookie("user", $myusername, time()+3600);//sets our user cookie
setcookie("pass", $mypassword, time()+3600);//sets our pass cookie
header("Location:../index_pinit.php");
}
else {
header("location:../oops.html");
}
What am I doing wrong? Why can't I read the cookies back?