Page 1 of 1

Session Unset killing ALL sessions including user register ?

Posted: Fri Aug 31, 2007 2:56 pm
by jramaro
hi
I have to unset sessions at the beginning of every page because i have website where a php script operates in an
iframe (because Im not good with ajax yet)

it works good. the problem is when you go to another page the script is set by things previously set on another page
and they're irrelavent to the new page.

So i used session unset(). and it worked. but its also killing off the user_email session.
I used unset() like this as example:

Code: Select all

<?php
session_start(); 
$_SESSION['user_email']; 
?>
<?php 
session_unset($_SESSION['product_1'] );
session_unset($_SESSION['product_2'] );
session_unset($_SESSION['product_3'] );
?>


Nowhere did i turn off the user_email but its slappin it out of there .
what do you think?

Thank You

Posted: Fri Aug 31, 2007 3:27 pm
by feyd
session_unset() does not take any parameters. As the documentation says "The session_unset() function frees all session variables currently registered."

Posted: Fri Aug 31, 2007 3:40 pm
by jramaro
oh, that makes perfect sense then.

i was reading on php.net
where they said "use unset() to unregister a session variable, i.e. unset ($_SESSION['varname']); "
So i assumed wrong by thinking they could be individually unset()

and i read where they say if im using $_SESSIONS that i shouldnt do this :
" If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister()."

and the other sessions say :

session_unset( ['varname'] = is no good
session_unregister = they say is no good

session_destroy says " It does not unset any of the global variables associated with the session"

So, Im not sure which session im supposed to use to unset or undo that without destroying the user_email session
because its related to the login.

Any ideas or links that might say = "this is the session for unsetting specific sessions, without destroying the rest" ?

Thank You

Posted: Fri Aug 31, 2007 3:41 pm
by feyd
They can be individually be unset().