(PHP 4, PHP 5 < 5.4.0)
session_is_registered — 检查变量是否在会话中已经注册
$name
)检查变量是否已经在会话中注册。
本函数已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。
name
变量名称。
session_is_registered() 返回 TRUE
则表示 name
变量已经在当前会话中注册使用,否则返回 FALSE
。
Note:
如果使用 $_SESSION (或 $HTTP_SESSION_VARS for PHP 4.0.6 or less),可以使用 isset() 检查变量是否在 $_SESSION 中注册使用。
如果使用 $_SESSION (或 $HTTP_SESSION_VARS), 则不要使用 session_register(), session_is_registered() 和 session_unregister().
paimpozhil at gmail dot com (2013-04-07 16:54:15)
For those who have an older application which uses the session_is_registered..and you want to use that in php5.4
You can just define the function if required
function session_is_registered($x)
{
if (isset($_SESSION['$x']))
return true;
else
return false;
}
May be add the checks to ensure function is not already existing..
amol_bhavsar1982 at hotmail dot com (2009-03-22 23:47:56)
session_register() function is generating warnings. Therefore, instead of using:
<?php
$test = 'Here';
session_register('test');
?>
It is better :
<?php
$_SESSION['test'] = 'Here';
?>
somedude at wholikesphp dot com (2002-10-31 10:02:48)
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 (2002-06-13 04:27:04)
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.