Re: Problem with is_array() and empty() for $_SESSION...
| From: | Scott Fletcher | Date: | Fri, 14 Nov 2003 17:31:37 +0000 |
| Subject: | Re: Problem with is_array() and empty() for $_SESSION... | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-169659@lists.php.net to get a copy of this message | ||
Sorry for the duplicate... MS-Outlook Express returned an error message
saying it had socket problem with PHP newsgroup.
"Scott Fletcher" <scott@abcoa.com> wrote in message
news:20031114172115.70837.qmail@pb1.pair.com...
> Thanks for jogging my memory. I seem to be so focus on this for a couple
of
> hours and didn't happen to see that I make one minor typo with adding the
> six $_SESSION data. I assign the odbc_result() to it, so forgot to
> increment the number on one of them, so the rest after it was off by one.
> So, it's my fault.
>
> One question though, wouldn't it make more sense to have the result be
> either as 0 or 1 (or true or false) instead of blank or 1. I first
> interpret the blank as something is wrong with the script or functions.
>
> Thanks,
> Scott F.
>
> "Chris Shiflett" <shiflett@php.net> wrote in message
> news:20031114165938.98959.qmail@web14306.mail.yahoo.com...
> > --- 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