PHP question on sessions

stndn

Golden Member
Mar 10, 2001
1,886
0
0
I'm just wondering..
assume i create session variables using
$_SESSION['userid'] = "username";
$_SESSION['password'] = "password";
$_SESSION['admin'] = "admin";

then i unset them using:
unset ($_SESSION['userid']);
unset ($_SESSION['password']);
session_destroy();

Taking this piece of information in mind:
session_destroy() destroys all of the data associated with the current session

will the call to session_destroy() also delete the value in $_SESSION['admin']?
or will it stay since i didn't explicitly unset $_SESSION['admin']?
my guess is that all the session variables will be gone (the keys and values), but i just want to verify...

btw, if l leave out the session_destroy() from the two unset()'s, is it bad?
When i use the session variables, i always check for the values in it (not only checking if it exists), so ...

thanks.
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
Sorry your guess is wrong, in a way. If you do like you did above you would still be able to print and access the $_SESSION['admin'] variable. But if you ran session_start() then you would no longer be able to access it. When is says it destroys all data associated with the session, it does but it does not unset variables already registered with the superglobal $_SESSION but by starting a new session with nothing registered in it it effectively gets rid of the $_SESSION['admin'] in that you destroyed the session and it reset $_SESSION to a empty array. I hope this helps if you have any more questions just ask.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
so that means the variable $_SESSION['admin'] will still be available as long as i don't call session_start() following a session_destroy()?