Page 1 of 1
OR operator in if statements
Posted: Wed Aug 11, 2010 8:49 pm
by marvolo1300
Hi, could someone tell me if used the right syntax for the if (x||y) statement?
This is the error
unexpected T_BOOLEAN_OR on line 2
Code: Select all
if (!isset($_COOKIE['login']))||($_COOKIE['login'] != $hash) // line 1
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">';
}
Re: OR operator in if statements
Posted: Wed Aug 11, 2010 9:35 pm
by PHPHorizons
Hello marvolo1300,
You're close, but you closed the if block "conditional" immediately after the !isset() part. Moving that closing parenthesis to the end of that line will correct the problem:
Code: Select all
if (!isset($_COOKIE['login']) || ($_COOKIE['login'] != $hash)) // line 1
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">';
}
Cheers
Re: OR operator in if statements
Posted: Fri Aug 13, 2010 12:50 pm
by marvolo1300
Thanks it worked. I also figured out that i don't need to check if login cookie exists.
Re: OR operator in if statements
Posted: Fri Aug 13, 2010 1:17 pm
by PHPHorizons
You're welcome
lol, that's ironic

Cheers
Re: OR operator in if statements
Posted: Fri Aug 13, 2010 1:57 pm
by AbraCadaver
marvolo1300 wrote:Thanks it worked. I also figured out that i don't need to check if login cookie exists.
If you're concerned about proper programming and not generating E_NOTICES for non-existent variables, then yes, you do need to check at some point before attempting to use/compare the variable.