By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

does checking what sessions var contain implicitly check for it's existance?

P: n/a
In other words if I want to check if $SESSION['temp'] = 'A',
do I also NEED to check isset($_SESSION['temp']) ?

If so, what logical IF statement works? I f have tried for an hour to come
up with a IF statement that works:

if ((isset($_SESSION['temp']))AND($_SESSION['temp'] = 'A'))
echo "set and same";
else
echo "not (set & same)";

if ((!isset($_SESSION['temp']))OR(!$_SESSION['temp'] = 'A'))
echo "not set or not same";
else
echo "set or same)";

None seem to work

Thanks for help.


Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <_D*******************@bignews2.bellsouth.net>, NotGiven wrote:
In other words if I want to check if $SESSION['temp'] = 'A',
= is for assignment. == is used for comparision.
if ((isset($_SESSION['temp']))AND($_SESSION['temp'] = 'A'))


I don't know (read too lazy to look it up right now) if there is
somewhere defined how multiple conditions will be evaluated (as in from
left to right or from right to left or random).

But untill now testing first if the variable isset, and then testing if
it equals something has always worked.

if (isset($foo) && $foo == 'bar')
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #2

P: n/a
NotGiven wrote:
If so, what logical IF statement works? I f have tried for an hour to come
up with a IF statement that works:
You almost got it :)
if ((isset($_SESSION['temp']))AND($_SESSION['temp'] = 'A'))

^^^

The "=" is the assignment operator, you need the 'test for equality'
operator:

if ((isset($_SESSION['temp'])) AND ($_SESSION['temp'] == 'A'))
^^^^

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3

P: n/a
"NotGiven" <no****@nonegiven.net> wrote in message
news:_D*******************@bignews2.bellsouth.net. ..
In other words if I want to check if $SESSION['temp'] = 'A',
do I also NEED to check isset($_SESSION['temp']) ?


No, you don't need to. Accessing an undefined variable yields null, which
automatically gets converted to an empty string when you do a string
comparison. So if($_SESSION['temp'] == 'A') would be false if
$_SESSION['temp'] wasn't set.

If error_reporting is set to show E_NOTICE, do this to suppress the warning:

if(@$_SESSION['temp'] == 'A') {
}

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.