Re: Problem with is_array() and empty() for $_SESSION...

From: Date: Fri, 14 Nov 2003 16:59:38 +0000
Subject: Re: Problem with is_array() and empty() for $_SESSION...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-169654@lists.php.net to get a copy of this message
--- Scott Fletcher <scott@abcoa.com> wrote: > session_start(); > > print_r($_SESSION); > //This one work because it spitted out datas from previous webpage > > echo (!(is_array($_SESSION))); > //This spitted out result as a blank This is because echo deals with strings. The boolean false is the empty string when converted. Because $_SESSION is an array, your is_array() returns true, and your not (!) makes the expression false. > echo empty($_SESSION[USER_ID]); > //This spitted out result as "1" Because you have not set this variable (at least, not in the code you provided), empty() returns true. The boolean true will be output as 1. > echo empty($_SESSION[CUSTOMER_ID]); > //This spitted out result as a blank This means $_SESSION['CUSTOMER_ID'] is not empty. > echo empty($_SESSION[USER_LOGON1]); > //This spitted out result as "1" This means $_SESSION['USER_LOGON1'] is empty. > echo empty($_SESSION['PHPSESSID']); > //This spitted out result as "1" This means $_SESSION['PHPSESSID'] is empty. > I have no idea what is the problem here. Do my comments help? If you are wondering why some things are defined and others are not, please show us the output of print_r() in addition to these conditional statements, and we can compare the results. Otherwise, we have to assume that your conditional statements are working as expected. Hope that helps. Chris ===== Chris Shiflett - http://shiflett.org/ PHP Security Handbook Coming mid-2004 HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp

« previous php.general (#169654) next »