简体   繁体   中英

PHP logout fails to log user out

my name is Sven and im experiencing a problem with loggin out of my site. My login code is the following:

$_SESSION['userName'] = $userName;
header("location:success.php");

I've tried several logout codes like session_destroy(); and session_unset(); but non of them seems to log the user probertly out. Please help

Without seeing any of your actual logout code....Im just gonna go ahead and take a wild guess here....

My guess is you just didn't include session_start(); at the top of your logout script....

95% of the time, that is the reason for logouts failing. Is that people just call session_destroy() but they forget that they still have to start the session on that page, so that the destroy() function knows there is a session to destroy...

Let me know if that was your problem :)

I have this code:

session_name('frontpage');
session_start('frontpage');
session_unset('frontpage');
session_destroy();
header("Location:index.php");

I hope may help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM