I'm having a problem with cookies, and this is really my last resort for help 🙂
my code's a "simple" login script that doesnt appear to be working..
first it logins in the user using this function,
function login($user_name, $password) {
$db = "localhost";
$SQL = "SELECT * FROM users WHERE user_name ='$user_name'";
$connection = db_connect();
$query = mysql_db_query($db, $SQL, $connection);
$row = mysql_fetch_array($query);
if (($row[ "user_name"] == $user_name)
AND ($row[ "password"] == $password)
AND ($user_name != "")) {
$user_id = $row[ "user_id"];
$md5pw = md5($password);
setcookie("Login", "$user_id:$md5pw", time()+3600);
$value = 1;
} else {
$value = 0;
}
return $value;
}
a successful login(gavin,blah) sets a cookie with the userid and the password, but I cant retrieve it.. eg
function verify_auth($cookie) {
$auth = explode( ":", $cookie);
$db = "localhost";
$connection = db_connect();
$SQL = "SELECT * FROM users WHERE user_id = '$auth[0]'";
$query = mysql_db_query($db, $SQL, $connection);
$row = mysql_fetch_array($query);
$md5pw = md5($row[ "password"]);
if (($row[ "user_id"] == $auth[0])
AND ($md5pw == $auth[1])
AND ($auth[0] != "")) {
$value = 1;
} else {
$value = 0;
}
return $value;
}
after logging in and checking verify_auth(Login) it returns 0, despite the cookie being set.
$check = verify_auth(Login);
print $check;
...returns 0
I'm running win98 with php4 latest ver and mysql win32 shareware latest ver, and ie 6.0.. can anybody see what the problem is? It's probably something very simple, but it's extremely annoying.. any feedback is appreciated.
thanks.
Gavin.