Setting a cookie as a variable
Posted: Sun Jul 05, 2009 10:34 am
I'm getting an error in my code when a users logged in. They can login fine, and it uses a cookie to store their username and password. When they go to a user control panel page, it checks that the password cookie matches the password in the database (they're both encrypted) and then shows the data. If they two don't match, it redirects to the login page.
Now, this part all works fine.
Later in the script though, where I use $username to retrieve information from the database, it errors me and says the variable hasn't been set.
Specifically, there are 3 occasions, with this being the first of them-
It manages to give me the result, and error me saying the variable isn't set. This is quite worrying, and later on in the script it doesn't provide the output, and I just get an error saying that the variable isn't set.
Code: Select all
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
}
else {
header('Location: index.php?content=login'); }
if (isset($_COOKIE['password'])) {
$password = $_COOKIE['password'];}
else {
header('Location: index.php?content=login'); }
$getpassq = mysql_query("SELECT User_pass FROM aero_users WHERE User_name = '$username'");
$getpassa = mysql_fetch_assoc($getpassq);
$getpass = $getpassa['User_pass'];
if ($getpass != $password) {
header ('Location: index.php?content=login'); }
}Later in the script though, where I use $username to retrieve information from the database, it errors me and says the variable hasn't been set.
Specifically, there are 3 occasions, with this being the first of them-
Code: Select all
$getmsg = mysql_query ("SELECT * FROM aero_mail WHERE Message_Recipient = '$username' AND Message_New = '1'");