Jump to content

Cookies will NOT delete.


marcus

Recommended Posts

Ok. What I'm doing is checking to see whether the UID and Encrypted Password combination is correct.

 

if($need_log > 0){
$sql = "SELECT * FROM `users` WHERE `id`='{$_COOKIE['uid']}' AND `password`='{$_COOKIE['cpp']}'";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) == 0){
setcookie("uid","",time()-314496000);
setcookie("cp","",time()-314496000);
setcookie("cpp","",time()-314496000);
unset($_COOKIE);
header("Location: /index.php");
}
}

 

It does redirect the user to the index but the cookies remain unchanged and have the same values in the end. That's the exact code I have when the user wants to log out, and that works, but the code checked here does not work.

Link to comment
https://forums.phpfreaks.com/topic/75019-cookies-will-not-delete/
Share on other sites

Is this code being executed from a different path? I know cookies are pretty sensitive, so if you set them in /subpath/subpath2, then try to delete them from root or /subpath, it may not work. If you're not setting the path parameters explicitly when the cookie is created, try doing that, then stating the same parameters when you delete them. If that doesn't work, I don't have any idea what the problem might be. It seems strange that the deletion works on logout but not there.

Hm. So you're setting the cookies with setcookie("uid", [id], time() + 60*60*24*365, "/"). Did you try deleting it with setcookie("uid", "", time() - 3600, "/")? I didn't pick up from your post whether or not you're operating in the same path with both calls to setcookie(). That would certainly make a difference.

Archived

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

×
×
  • 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.