Same session variable with 2 different values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Same session variable with 2 different values

Post 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.
Last edited by impulse() on Sun Nov 12, 2006 10:32 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What are you expecting your code to do? And seriously, please use

Code: Select all

tags for all php code postings.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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']);.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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?
Post Reply