Click to See Complete Forum and Search --> : how to destroy individual session variables
damon2003
12-03-2003, 01:54 PM
Hi,
I know how to destroy a complete session-session_destroy();
but how do you destroy individual session variables as I want to keep some of the variables in a session?
thanks
what if you unset() (http://us3.php.net/manual/en/function.unset.php) it?
HTH
andymnc
12-03-2003, 05:17 PM
exact, you can simply use:
unset ($_SESSION["yoursessionvariable"]);
I like to use unregister()
If you use that method, you'd best be aware that it "does not unset the corresponding global variable for name, it only prevents the variable from being saved as part of the session."
http://us3.php.net/manual/en/function.session-unregister.php
damon2003
12-16-2003, 07:43 AM
Hi,
I am having trouble unregistering session variables.
I am attempting to unregister specific variables.
I get to a page, and us this:
I have tried this first, but it destroys all session variables
session_unset($_SESSION['textfieldFirstNameCustomerExisting']);
Next I tried this, but it doesnt seem to work at all
unset($_SESSION['textfieldFirstNameCustomerExisting']);
I am using $_SESSION
so , as I understand it session_unregister() does not work here
ani ideas here,
thanks
Are you remembering to run session_start() first? This should work fine:
<?php
session_start();
unset($_SESSION['session_name']);
?>
damon2003
12-16-2003, 07:54 AM
yes,
I have session_start() at the top of all my pages,
I then do some stuff with the session, and then right at the end call the unset().
If I replace this with session_unset() then this destroys all variables
damon2003
12-16-2003, 08:13 AM
Hi,
I got it working,
this works
session_unregister('textfieldFirstNameCustomerExisting');
when global variabled is turned on