Link to home
Start Free TrialLog in
Avatar of vertex_paul
vertex_paulFlag for United States of America

asked on

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?
Avatar of Tomeeboy
Tomeeboy
Flag of United States of America image

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.
Avatar of quad341
quad341

you may want to use exactly equal (===) instead of just equal (==) because automatic type conversion may be causing problems
Avatar of vertex_paul

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of quad341
quad341

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial