etonB Posted March 22, 2010 Share Posted March 22, 2010 I'm making a small website where an admin has special functions. I've managed to make my login/logout scripts with sessions and able to show the admin's special functions only to him. The problem is when logging out and back in, it gets really weird. This is how I can come accross the error: 1. Enter my website 2. Log-in as 'admin' 3. Click on Add News (the special functions) 4. At this point, things work perfect, I can add news and go back to main page. 5. Log-out 6. Log-in as 'admin' again 7. Click on Add News 8. At this point, I get logged out and can't add news obviously until I log in again. This is how I perform log-out <p class="textoIngresar">Welcome, <?php echo $_SESSION["loggedUser"];?> ( <a href="index.php?action=logout">Log-out</a> )</p> This is the actual log out function if ( $_GET["action"] == "logout") { session_unset(); session_destroy(); } Am I doing the logout wrong? I need to know if that part is ok so I can look for errors elsewhere. Thanks in advance, etonB. Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted March 22, 2010 Share Posted March 22, 2010 sounds more like a problem with your session settings in your php.ini. i used to get random logouts and it was related to the webhost's garbage collection process, which wiped my sessions out even if they weren't expired. also probably unrelated but good to know, sessions at www.yoursite.com and yoursite.com are NOT the same. i force the www to be there. Quote Link to comment Share on other sites More sharing options...
etonB Posted March 22, 2010 Author Share Posted March 22, 2010 I'm going to look into that (hosting @ ipage) later on because I don't actually have access to php.ini But the thing is, the logouts aren't random as they always happen when I do the steps shown. Is my logout done correctly? I've read other advice like doing $SESSION = array(); instead of unset_session(); but I'm clueless. Quote Link to comment Share on other sites More sharing options...
etonB Posted March 22, 2010 Author Share Posted March 22, 2010 I've talked with their tech support and they say the sessions settings on their end are good. Can anyone give me some input on the way I'm currently handling log-out? Quote Link to comment Share on other sites More sharing options...
Tazerenix Posted March 22, 2010 Share Posted March 22, 2010 foreach ($_SESSION as $key) { unset($key); } session_destroy(); That should unset all the session variables you have set and terminate the session. Its really just an alternative to the code your already using And try putting error_reporting(E_ALL) at the top of your script. It helps sometimes also, just incase, check that you do have a session_start() at the top of your page. Sometimes we forget it Quote Link to comment 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.