Cookie frustrations...
Date: 08/12/05
(PHP Community) Keywords: no keywords
So, I'm trying to make a simple script which will verify that a user has logged in.
When a user logs in, the following code is executed:
if ($HTTP_POST_VARS["rememberme"] == true) {
setcookie("Username", $HTTP_POST_VARS["username"], time()+60*60*24*30, "/");
setcookie("Validation", md5($HTTP_POST_VARS["username"]), time()+60*60*24*30);
} else {
setcookie("Username", $HTTP_POST_VARS["username"], 0);
setcookie("Validation", md5($HTTP_POST_VARS["username"]), 0);
}
The top branch of the if statement is if they had checked the "remember me" box, otherwise, the cookie should expire at the end of the session.
To log out the user, I want to delete the cookies set by the login script. I have tried pretty much everything that I could find.
- Setting the same cookies with a null value, and time to exipre in the past.
- Calling setcookie with the cookie name just by itself.
- Calling setcookie with the cookie name and values exactly the same, yet with a time in the past.
My current logout code involves:
setcookie("Username", "", time()-3600);
setcookie("Validation", "", time()-3600);
And the testing of the cookie is done on a seperate page altogether, so it shouldn't be the fact that cookies do not get set until after the page is rendered.
Am I missing something extremely trivial here?
Thanks in advance
Source: http://www.livejournal.com/community/php/334932.html