vertex_paul
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?
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?
you may want to use exactly equal (===) instead of just equal (==) because automatic type conversion may be causing problems
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.