Jump to content

Problem with logging out a user


Niixie

Recommended Posts

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] => [email protected] )

 

Anyone sees my problem?

Link to comment
https://forums.phpfreaks.com/topic/254359-problem-with-logging-out-a-user/
Share on other sites

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.