Forum Moderators: coopster
I'm writing a members login area with php and MySQL. I'm using setcookie to store my "logined" status after the username and password are verified. But I'm just wondering how to I write the logoff part?
Using session, I could just simply use session_destroy() to log off the user. But how do I do that in cookie?
But when you set the cookie, you gave it an expiration time (some time into the future), correct?
When the user logs out, to "destroy" the cookie... use PHP to alter/modify the cookie with a negative/old/past expiration.
With an "old" expiration, the browser will clear/delete the cookie, "logging off" your user.
Persistent cookies are set and updated with a specific expiration date in GMT format. These cookies will NOT go away when the browser is closed, but will only die when that expiration date has passed.
As mentioned, you can kill both by setting an expiration date in the past, but to work it has to be a valid format. An invalid date won't set properly.