Niixie Posted January 4, 2012 Share Posted January 4, 2012 Hey, i have a small problem with the logout part of my account system. When i click the logout link, it directs me to the index page with an error (custom error stuff i made). Heres my logout code <?php echo 'Behandler ...<br />'; if(isset($_SESSION['logged']) && isset($_SESSION['email']) && $_SESSION['logged'] == 1) { echo 'Logger ud, vent venligst...'; unset($_SESSION['logged']); unset($_SESSION['email']); header('location: index.php?p=success&ploca=login&pid=1'); exit(); } else { header('location: index.php?p=error&ploca=login&pid=5'); // This is where it jumps to directly. exit(); } ?> The weird thing is, that the sessions email and logged is set, as you can see here; //Printed with print_r($_SESSION); Array ( [psite] => index [logged] => 1 [email] => a@b.c ) Anyone sees my problem? Quote Link to comment https://forums.phpfreaks.com/topic/254359-problem-with-logging-out-a-user/ Share on other sites More sharing options...
Philip Posted January 4, 2012 Share Posted January 4, 2012 Make sure session_start() is at the top. Quote Link to comment https://forums.phpfreaks.com/topic/254359-problem-with-logging-out-a-user/#findComment-1304270 Share on other sites More sharing options...
ManiacDan Posted January 4, 2012 Share Posted January 4, 2012 Ok, this is a perfect example on how to debug on your own. Your question was: "My code goes right to the ELSE, what could be wrong?" The obvious (and only) answer to that question is "Your IF is resolving to FALSE." Now, look at the IF. There are three parts to the clause. var_dump all three. You'll find either: 1) $_SESSION['logged'] is not set 2) $_SESSION['logged'] is not equal to 1 3) $_SESSION['email'] is not set Or any combination of the three. Based on looking at your code, I agree with Philip. You'll find all three of the above conditions are true. If you were debugging this on your own, you'd follow up by saying "well then what the heck is even in the session!?" You'd find that nothing is in the session, which is when you slap your forehead and put session_start at the top. Quote Link to comment https://forums.phpfreaks.com/topic/254359-problem-with-logging-out-a-user/#findComment-1304271 Share on other sites More sharing options...
Niixie Posted January 4, 2012 Author Share Posted January 4, 2012 Thank you both. Quote Link to comment https://forums.phpfreaks.com/topic/254359-problem-with-logging-out-a-user/#findComment-1304273 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.