session_unset runs even if it is not supposed to.

I have a script with an if... else... statement.

I want to session_unset only if the else statement runs, but for some reason it runs no matter where it is located in the code.

Has anyone else experienced this problem?
LVL 2
vertex_paulAsked:
Who is Participating?
 
quad341Commented:
from your desciption, it sounds like it. what version of php are you running?
0
 
TomeeboyCommented:
It sounds like you just have a problem with how your code is structured.  If the unset is inside your else statement, it's going to get executed in every instance where the "if" part of the statement is not met.  Example:

if ($variable == "test") {
    // test code
} else {
    // unset code
}

Every time $variable is not equal to "test", your else code is going to be executed, including the unset.  Now, if you are passing a valid value that should only excute the top part of code (in this example, $variable would have to equal "test") and the "else" part of the statement is still being excuted, then you need to investigate the variables that are used in the "if" line of the statement.
0
 
quad341Commented:
you may want to use exactly equal (===) instead of just equal (==) because automatic type conversion may be causing problems
0
 
vertex_paulAuthor Commented:
The code is structured correctly, it is written exactly like the code in the comment from Tomeeboy, and the proper code is running.  The test code from the if statement is running when it is supposed to, but if I place the unset code in the else statement it also runs, but none of the other code in the else statement runs.  This is why it is so confusing.  Could it be a bug in php?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.