session_is_registered

(PHP 4, PHP 5 < 5.4.0)

session_is_registered전역 변수가 세션에 등록되었는지 확인

설명

bool session_is_registered ( string $name )

전역 변수가 세션에 등록되었는지 확인합니다.

Warning

이 함수는 PHP 5.3.0부터 배제됩니다. 이 기능에 의존하지 않기를 권합니다.

인수

name

변수명.

반환값

session_is_registered()는 전역 변수명이 name인 변수가 현재 세션에 등록되어 있으면 TRUE를, 아니면 FALSE를 반환합니다.

주의

Note:

$_SESSION(또는 PHP 4.0.6까지 $HTTP_SESSION_VARS)을 사용하면, $_SESSION에 변수가 등록되었는지 확인할 때 isset()을 사용하십시오.

Caution

$_SESSION(또는 $HTTP_SESSION_VARS)를 사용한다면, session_register(), session_is_registered(), session_unregister()를 사용하지 마십시오.

add a note add a note

User Contributed Notes 9 notes

up
8
pk at majstar dot com
9 years ago
There's an error in the comment posted by "someone at the dot inter dot net". Correct replacement for function session_is_registered() in PHP 5.4+ is

function session_is_registered($x) {return isset($_SESSION[$x]);}

so just $x instead of '$x' - single quotation mark won't interpolate the variable $x and the function will always return false.
up
3
amol_bhavsar1982 at hotmail dot com
15 years ago
session_register() function is generating warnings. Therefore, instead of using:

<?php
$test
= 'Here';
session_register('test');
?>

It is better :

<?php
$_SESSION
['test'] = 'Here';
?>
up
-9
someone at the dot inter dot net
10 years ago
A simple one-line function to emulate this in later versions of PHP:
function session_is_registered($x){return isset($_SESSION['$x']);}
up
-11
paimpozhil at gmail dot com
11 years ago
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..
up
-12
someone at the dot inter dot net
10 years ago
A simple one-line function to emulate this in later versions of PHP:
function session_is_registered($x){return isset($_SESSION['$x']);}
up
-8
miguel dot simoes at swirve dot com
22 years ago
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.
up
-14
vectorjohn at example dot com
10 years ago
The proper equivalent has nothing to do with isset().

Use array_key_exists() because session_is_registered returns true if the variable is in the session at all, even if it's falsy.
up
-19
Sami
10 years ago
I can not get the following code to work as it is returning an error on the session_is_registered() and do I have to change anything else in the code

Thank you

if(!session_is_registered('user_name')){

if (isset($_POST['username'])) {
$password1 = clean($_POST["password"]);
$username1 = clean($_POST["username"]);
$password2 = crypt($password1);

$result = @mysql_query ("select * from users where user_name = '".$username1."'");
$lim = @mysql_num_rows( $result );
//|| (strlen($username1) < 6) || (strlen($password1) < 6)
if( ($lim!=0)  ){
$row = @mysql_fetch_array($result);
$password=$row['user_password'];
if (crypt($password1, $password) == $password){
$sql = @mysql_query ("insert into logs (ip, cdate, status) values ('".$REMOTE_ADDR."','". date("Y-m-d H:i:s") ."', 'Login')");
session_register('user_id');
session_register('user_fullname');
session_register('user_name');

$_SESSION['user_name'] = $row['user_name'];
$_SESSION['user_fullname'] = $row['user_fullname'];
$_SESSION['user_id'] = $row['user_id'];
}//if crypt
else{
up
-18
CertaiN
10 years ago
If your session variables may have NULL value,  use array_key_exists() instead of isset(). If not, use isset() because it performs better than array_key_exists().
To Top