search for in the  
<session_idsession_module_name>
Last updated: Thu, 19 May 2005

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.

Note: 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.

Caution

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



User Contributed Notes
session_is_registered
steve at fakesterdesigns com
28-Jun-2004 10: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
17-Jun-2004 02: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 04: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.
sorr at see ess you ell bee dot edu
07-Nov-2003 05:41
The previous comment is bad code.  Don't copy it.
Here is a better code block.  Copy this.
===================================
<?php
// Start session and set variable.
session_start();
$_SESSION['theSESSIONvarName'] = "is_set";
// Check if the session is set.
if(isset($_SESSION['theSESSIONvarName']))
{
$sid = session_id();
echo
"<html>";
echo
"<head><title>PHP Session Is Set!</title></head>";
echo
"<body><p>The session is set! The PHPSESSID is: $sid</p></body>";
echo
"</html>";
}
else
{
echo
"<html>";
echo
"<head><title>PHP Session Is NOT Set!</title></head>";
echo
"<body><p>The session is NOT set! Check your server configuration or version.</p></body>";
echo
"</html>";
}
?>
Eddie at NoveltyNeckties dot com
29-Oct-2003 11:20
Create a page named "CheckSession.PHP".

Put this inside its source code.

<?php
session_start
();
$_SESSION['theSESSIONvarName'] = "is_set";
// Check if the session is set.
if(!isset($_SESSION['theSESSIONvarName']))
{
echo
"<HTML>";
echo
"<HEAD>";
echo
"<TITLE>Session Is Set! - PHP: Hypertext Processor</TITLE>";
echo
"";
echo
"</HEAD>";
echo
""
echo "<BODY>";
echo
"";
echo
"<P>The session is set! The PHPSESSID is:</P>";
echo
"<P>session_id();</P>";
echo
"";
echo
"</BODY>";
echo
"</HTML>";
}
{ else }
echo
"<HTML>";
echo
"<HEAD>";
echo
"<TITLE>Session Is Not Set! - PHP: Hypertext Processor</TITLE>";
echo
"";
echo
"</HEAD>";
echo
"";
echo
"<P>The session is NOT set! It should be -- it is in the source code - look for it at the BEGINNING of the file, not looking at the source -- in the real file!</P>";
echo
"";
echo
"</BODY>";
echo
"</HTML>";
?>
--------------------END--------------------
Go to that page. Then you should see a page with the following on it:

The session is set! The PHPSESSID is:

40ut89wur8m904ur08m4mu8tu48tu8u

-------
I created that PHPSESSID myself, yours will probably be something different.

Thanks,
Eddie at NoveltyNeckties dot com
somedude at wholikesphp dot com
31-Oct-2002 12: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 06: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.

<session_idsession_module_name>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT