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] => a@b.c )

 

Anyone sees my problem?

Link to comment
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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.