session_is_registered

(PHP 4, PHP 5)

session_is_registered --  Find out whether a global variable is registered in a session

Description

bool session_is_registered ( string name )

session_is_registered() returns TRUE if there is a global variable with the name name registered in the current session.

注: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use isset() to check a variable is registered in $_SESSION.

注意

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
steve at fakesterdesigns com
29-Jun-2004 11:21
since it seems a little tedious to use $_SESSION['var'] all over my code, I just make a reference at the start of my page and use the simple reference name thereafter.

<?
session_start
();

$myName = &$_SESSION['myName'];

echo(
$myName);

?>

This is, of course, only a reference and not a copy. So if you change the local variable, It'll be changed in the $_SESSION global array as well. This could be good or bad, so just be aware of what you're doing.
Tuukka from Finland
18-Jun-2004 03:16
From the previous note:
--------------------------------------------------
So, forget session_register(), session_unregister(), session_destroy() and al those stupid functions. The only thing you need is the super global $_SESSION.
--------------------------------------------------

I do have to disagree about the session_destroy() function; if you want to remove the session file created in the server tmp or whatever folder, you must use session_destroy() function.

The <?php $_SESSION = array(); ?> code only unsets the superglobal variables.

For clearing the superglobals, the cookie and deleting the server session file, my advice would be using the code below.

<?php

//session_start(); // if your session wasn't started yet
setcookie(session_name() ,"",0,"/");
unset(
$_COOKIE[session_name()]);
$_SESSION = array();
session_unset();
session_destroy();

?>
webmaster __AT__ digitalanime __DOT__ nl
22-Feb-2004 06:47
Do not use this anymore!

As of PHP 4.* the super globals are used, so you have to FORGET this function. Super globals are way more safe and they are exactly what they have to be: Clear.

$_POST says that variables in that array come from a form.
$_GET says that variables are passed through the URI.
$_SESSION says (more than clear) that variables are in a session.

USE THEM! They are not there because of their beauty or something..

So, forget session_register(), session_unregister(), session_destroy() and al those stupid functions. The only thing you need is the super global $_SESSION.
somedude at wholikesphp dot com
01-Nov-2002 02:02
Just to elaborate for those who may be having some problems.
If you're using a newer version of PHP that comes with the register globals directive set to "off", you should heed the caution at the top of these notes. It's easier anyway.

Instead of using session_register(...) , simply use somethig like:

<?
//must always start the session first
session_start();

//in place of session register(..) use...like someone said above
$_SESSION['VARNAME'] = $something // or "something";

/* then on the same page or subsequent pages where you want check for the session use something like....

and on another page where the session hasn't been started you have to call session_start(); first, if the session has already been started you don't need to call it again */

session_start();

//instead of session_is_registered();
if(isset($_SESSION['VARNAME']))
{
   print(
"What you want if the session var is set");
}
else
{
   print(
"What you want if the sessions variable is not set");
}

?>

I hope this helps someone! If you want to learn more about $_SESSION and/or it's related "superglobals" try

http://www.php.net/manual/en/printwn/language.variables.predefined.php

good road!
miguel dot simoes at swirve dot com
13-Jun-2002 07:27
When using PHP 4.2.0 even on the same page where you registered the variable with:

session_register("someVar");

if you try to see if the variable is set and do not assign it a value before, the function used in the previous comment will give the same output.
 This may show that the variable is declared and will not be set until some value is give assign to it.
 I think that this way will give the option to register all the variables used for sure on the process on the first page and using them as the time comes.