dmhall0 Posted February 10, 2012 Share Posted February 10, 2012 For some reason my logout is not working properly. I searched other forum posts and read some tutorials but I still have an issue. Do this to create session: $_SESSION['username'] = $row['username']; setcookie('username', $row['username'], time() + (60 * 60 * 24 * 5)); Do this to log out the user session_start(); session_unset(); $_SESSION = array(); setcookie(session_name(), '', time() - 3600); session_destroy(); setcookie('username', '', time() - 3600); Above all else I am trying to end the $_SESSION['username'] Thank you all Quote Link to comment https://forums.phpfreaks.com/topic/256782-logout-user-not-working/ Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 I don't work with cookies much but it seems the last call you should make is session_destroy(); session_start(); session_unset(); $_SESSION = array(); setcookie(session_name(), '', time() - 3600); setcookie('username', '', time() - 3600); session_destroy(); Quote Link to comment https://forums.phpfreaks.com/topic/256782-logout-user-not-working/#findComment-1316410 Share on other sites More sharing options...
delickate Posted February 10, 2012 Share Posted February 10, 2012 do this unset($_session); Hope it'll work for you. Quote Link to comment https://forums.phpfreaks.com/topic/256782-logout-user-not-working/#findComment-1316446 Share on other sites More sharing options...
dmhall0 Posted February 10, 2012 Author Share Posted February 10, 2012 That didn't work. It gave me this error message: Fatal error: Can't use function return value in write context I tried putting session_destroy() last and it works on Chrome, but still not logging out on Firefox, Opera, or IE. Makes no sense. Quote Link to comment https://forums.phpfreaks.com/topic/256782-logout-user-not-working/#findComment-1316519 Share on other sites More sharing options...
PaulRyan Posted February 10, 2012 Share Posted February 10, 2012 The code you have posted, is that all that is in your logout file? Quote Link to comment https://forums.phpfreaks.com/topic/256782-logout-user-not-working/#findComment-1316556 Share on other sites More sharing options...
dmhall0 Posted February 10, 2012 Author Share Posted February 10, 2012 Yes, that is it. And the only session variable I have is for the username. Quote Link to comment https://forums.phpfreaks.com/topic/256782-logout-user-not-working/#findComment-1316558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.