I have a script that should log the user out of the site. It unsets all $_SESSION and $_COOKIE variables related to the login data of the user. But somehow, it seems impossible to log out. I checked the $_SESSION array at the end of the logout script, and at the beginning of each page. At the end of the logout script it says 'array()', but when I click the home button - or any link on the site - the full session data is back again and I don't know where it comes from. This is how I try to unset the session data:
unset($_SESSION);
unset($_COOKIE["usid"]);
unset($_COOKIE["pw"]);
unset($_COOKIE["adm"]);
-- I don't know how to put it on different lines, but it's not that hard to read.
Why do these data keep coming back?!
views:
33answers:
1
A:
The PHP documentation says "Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal."
Try out this in stead: $_SESSION = array(); (as recommended on the PHP documentation).
Pino
2010-05-04 10:19:50
Ah, right! Thank you. I thought I knew how to work with sessions, but I never read that. Also, normally I would use unset($_SESSION[userID]); for example, but I guess I made a mistake there and forgot to unset a few specific important variables. Anyway, thanks for your help!
RemiX
2010-05-04 12:01:07