Session Unset killing ALL sessions including user register ?

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
jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

Session Unset killing ALL sessions including user register ?

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

Post by feyd »

session_unset() does not take any parameters. As the documentation says "The session_unset() function frees all session variables currently registered."
jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

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

Post by feyd »

They can be individually be unset().
Post Reply