Page 1 of 1

Same session variable with 2 different values

Posted: Sun Nov 12, 2006 10:24 am
by impulse()
Is it possible that $_SESSION["<name>"] can have 2 values?

I have a logout button on my site that runs the following code:

Code: Select all

session_destroy();
session_unset();
$_SESSION["username"] = NULL;
But still $_SESSION["username"] keeps it's value.

Posted: Sun Nov 12, 2006 10:27 am
by feyd
What are you expecting your code to do? And seriously, please use

Code: Select all

tags for all php code postings.

Posted: Sun Nov 12, 2006 10:31 am
by impulse()
Sorry about the tags.

I'm expecting to destory any data contained within $_SESSION["username"], failing that I was expecting the value of $_SESSION["username"] to change to anything that wasn't its inital assiged value.

My DB queries run on the basis of

Code: Select all

SELECT * FROM somewhere WHERE customerid = '$_SESSION["username"]'
My sites coded so that these queries will still run if a user isn't logged it but no data will be retrieved because the session variable will be empty.

Posted: Sun Nov 12, 2006 10:35 am
by feyd
It may be a good idea to take note of the .. note on the session_unset() page.
Note: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable, i.e. unset ($_SESSION['varname']);.

Posted: Sun Nov 12, 2006 10:43 am
by impulse()
Even after taking note, the value remains.

The session variable is set inside of a login function and then is unset outside of that function. I didn't think this would cause a problem due to session being a global, do you agree?