aebstract Posted March 10, 2008 Share Posted March 10, 2008 I'm using this code to completely clear all sessions and reset the session id back to what it was. This way whoever is logged in will remain logged in and all sessions that were set while they have been logged in, will be cleared. Is there a better way of doing this? It isn't keeping the user logged in like it is supposed to. $sessionid = $_SESSION["id"]; unset ($_SESSION); session_destroy(); $_SESSION["id"] = $sessionid; Quote Link to comment https://forums.phpfreaks.com/topic/95485-resetting-session/ Share on other sites More sharing options...
Psycho Posted March 10, 2008 Share Posted March 10, 2008 Hmm, I'm not 100% sure, but I'm thinking that destroying the session is causing the problem. Try removing just that line, or you can try this (might be less efficient, but should do what you are looking for): <?php //Unset all SESSION values except 'id' foreach ($_SESSION as $index => $value) { if ($index!='id') { unset($_SESSION[$index]); } } ?> EDIT: Found this in the manual (emphasis added): If you are creating a new session, but want to make sure that there are currently no sessions active by doing session_destroy(); make sure you start the session again using session_start(); or else your session data will not register properly. Quote Link to comment https://forums.phpfreaks.com/topic/95485-resetting-session/#findComment-488803 Share on other sites More sharing options...
aebstract Posted March 10, 2008 Author Share Posted March 10, 2008 That worked like a charm, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/95485-resetting-session/#findComment-488809 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.