Setting a cookie as a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Setting a cookie as a variable

Post by Sephern »

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.

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'); }
}
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-

Code: Select all

 
$getmsg = mysql_query ("SELECT * FROM aero_mail WHERE Message_Recipient = '$username' AND Message_New = '1'");
 
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.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: Setting a cookie as a variable

Post by Sephern »

Doesn't matter, fixed it.

I forgot to put in the function arguments. It's been a long day =[
Post Reply