Jump to content

Archived

This topic is now archived and is closed to further replies.

Balmung-San

Cookies won't set?

Recommended Posts

Okay, I've got this script that's [i]supposed[/i] to check for the existance of a cookie, wether or not the user exists based on the value of the cookie, and whether the password(contained in another cookie) is valid. However, it seems that it's not working correctly when the cookie doesn't exist. Any help?

[code] if(isset($_COOKIE['hd_amv_user']))
{
if(!isset($_COOKIE['hd_amv_pass']))
{
setcookie("hd_amv_user","Guest",(time()+24*3600*9999));
setcookie("hd_amv_pass","",(time()+24*3600*9999));
}
else
{
$passCheckSql = mysql_query("SELECT * FROM amv_users WHERE username='".$_COOKIE['hd_amv_user']."'");
if(mysql_num_rows($passCheckSql) > 1 || mysql_num_rows($passCheckSql) == 0)
{
setcookie("hd_amv_user","Guest",(time()+24*3600*9999));
setcookie("hd_amv_pass","",(time()+24*3600*9999));
}
else
{
$passCheck = mysql_fetch_array($passCheckSql);
if(strcasecmp($_COOKIE['hd_amv_pass'], $passCheck['password']) != 0)
{
setcookie("hd_amv_user","Guest",(time()+24*3600*9999));
setcookie("hd_amv_pass","",(time()+24*3600*9999));
}
}
}
}
else
{
setcookie("hd_amv_user","Guest",(time()+24*3600*9999));
setcookie("hd_amv_pass","",(time()+24*3600*9999));
}
[/code]

Share this post


Link to post
Share on other sites
Sorry for the double post, I fixed that one, but now my logout script doesn't work. I do the setcookie() calls first thing in my script, set them both to blank with an expire time of time()-3600. Shouldn't that erase the cookies?

Oh, and I run the above script after I supposedly erased them.

Share this post


Link to post
Share on other sites
[quote author=Balmung-San link=topic=110097.msg444440#msg444440 date=1159651163]
my logout script doesn't work. I do the setcookie() calls first thing in my script, set them both to blank with an expire time of time()-3600. Shouldn't that erase the cookies?
[/quote]

As you haven't posted your code for expiring the cookies, I have to guess what it looks like, but one piece of advice is make sure you you set it with the same amount of parameters.

From the manual...
[quote]
Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client.[/quote]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.