Jump to content

Cookies won't set?


Balmung-San

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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.