Page 1 of 1

[SOLVED] HELP NEEDED - Comparison operator not working

Posted: Thu Jul 15, 2004 6:16 pm
by RobertGonzalez
I am trying to force a page to load only when a certain query string is valid and only when the passed value is a certain value. I am using an if statement which works almost completely. The problem I am getting is that the value '0' (the number zero) should not be allowed to load the page. But when I enter it in the query string, the page loads anyway. All other 'unacceptable' values are kicked out and the result is what you would expect when looking at the code. Can someone please tell me what I am doing wrong? Thanks for all your help.

Code: Select all

<?php
if ( !(isset($_GET['dealer'])) || ($_GET['dealer'] >= 3) || ($_GET['dealer'] == 0) || !(is_numeric($_GET['dealer'])) )
{
	header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "dealers.php");
	exit();
}
?>
PS I have tried changing the comparison on the 'zero' issue. Using greater thans, less thans or equals to has yielded the same result.

Posted: Thu Jul 15, 2004 6:24 pm
by lostboy
if ( !(isset($_GET['dealer'])) || ($_GET['dealer'] >= 3) && ($_GET['dealer'] != 0) || !(is_numeric($_GET['dealer'])) )

Posted: Thu Jul 15, 2004 6:42 pm
by feyd
precedence may make that run a bit odd, Bastien.

Code: Select all

if ( !isset($_GET&#1111;'dealer']) || !is_numeric($_GET&#1111;'dealer']) || (($_GET&#1111;'dealer'] >= 3) && ($_GET&#1111;'dealer'] != 0)) )

Posted: Thu Jul 15, 2004 7:44 pm
by lostboy
yeah, it seemed a little screwy...maybe if i had some idea of what the acceptable values are?

Posted: Thu Jul 15, 2004 8:18 pm
by JAM
Why not...

Code: Select all

if ( empty($_GET['dealer']) or !is_numeric($_GET['dealer']) or abs($_GET['dealer']) > 2 )
The 0 (not allowed) is the same as FALSE, so empty() will trigger it. Added abs() to get rid of the possible =-1 idea some people might have...

Posted: Sat Jul 17, 2004 9:59 am
by RobertGonzalez
Thanks Jam, that snippet worked out perfectly. I appreciate everyone's help.