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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
you may want to use exactly equal (===) instead of just equal (==) because automatic type conversion may be causing problems
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?
from your desciption, it sounds like it. what version of php are you running?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.