session_unregister

(PHP 4, PHP 5)

session_unregister --  Unregister a global variable from the current session

Description

bool session_unregister ( string name )

session_unregister() unregisters the global variable named name from the current session.

This function returns TRUE when the variable is successfully unregistered from the session.

注: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable. Do not unset() $_SESSION itself as this will disable the special function of the $_SESSION superglobal.

注意

This function does not unset the corresponding global variable for name, it only prevents the variable from being saved as part of the session. You must call unset() to remove the corresponding global variable.

注意

If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister().


add a note add a note User Contributed Notes
Martin Pilka
18-May-2005 04:19
Same here. Unless I use session_unregister('varname') after unset(), varname is unset in current request, but set again in following request.

I use $_SESSION[] array, register_globals is off. session_unregister() is needed in spite what documentation says. PHP 4.1.2, Debian, package "php4 4.1.2-7.0.1".
dylan82 AT xs4all DOT nl
09-Dec-2004 05:13
If globals is on, you'll have to unset the $_SESSION[varname] as well as the $varname.

Like:

unset($_SESSION[varname]);
unset($varname);
jsmith at uncommoner dot com
27-Nov-2004 02:55
as a side note you must have session_start() set inorder to actually unregister the session varibles.
Somatik
11-Aug-2004 03:30
In reply to the above comment. If you forget the session_start(); you might have that problem. unset($_SESSION("varname")); works fine here.
jop at yes2web dot nl
28-Jun-2004 08:33
It took me some time to figure this out:
If you have register globals off, you probably use $_SESSION to acces you session vars. If you want clear a sessionvar inside the current script, but also in next pages, do this as follows:

session_unregister('varname');

Otherwise varname will keep returning either inside the script, or on the next pages.

unset($_SESSION['varname']) will only unset the session var on the current page.