Skor Posted September 29, 2007 Share Posted September 29, 2007 I'm trying to evaluate 2 different values in an IF statement -- basically allowing only authorized URLs to post to the page. I'm able to get each URL to work individually, but I'm not able to get both to be evaluated. Where would I put the OR. Here's what I've got. $ref = $_SERVER['HTTP_REFERER']; If ($ref != "http://www.sitename.com/post1.php") { echo "<head><title>Invalid Request</title></head>"; echo "This operation cannot be performed. Please go to <a href=\"http://www.sitename.com\">www.carolynkedesigns.com</a> to order. </font>"; } I want to say: If ($ref != "http://www.sitename.com/post1.php OR http://www.sitename.com/post2.php") but that didn't work and have been able to find an example of how to do this so I'm stuck. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/ Share on other sites More sharing options...
teng84 Posted September 29, 2007 Share Posted September 29, 2007 sytax if (condtion1 || condition2) if ($x==1 || $x=='teng') echo 'astig'; Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357718 Share on other sites More sharing options...
btherl Posted September 29, 2007 Share Posted September 29, 2007 If you want to check many urls: $urls = array( 'http://www.blah.com/post1.php', 'http://www.blah.com/post2.php', ); if (in_array($test_url, $urls)) { print "Allowed"; } else { print "Not allowed"; } Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357720 Share on other sites More sharing options...
Skor Posted September 29, 2007 Author Share Posted September 29, 2007 I tried this and it didn't work. If ($ref != 'http://www.sitename.com/page1.php' || $ref != 'http://www.sitename.com/page2.php') { echo Looks like the array solution only evaluates one value unless I'm incorrect here. Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357723 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 <?php If ($ref !== "http://www.sitename.com/post1.php" || $ref !== "http://www.sitename.com/post2.php") { echo "<head><title>Invalid Request</title></head>"; echo "This operation cannot be performed. Please go to <a href=\"http://www.sitename.com\">www.carolynkedesigns.com</a> to order. </font>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357726 Share on other sites More sharing options...
Skor Posted September 29, 2007 Author Share Posted September 29, 2007 Unfortunately, this didn't work. I went back to != and played with single and double quotes and still got my error message. Thanks for the ideas. Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357729 Share on other sites More sharing options...
markjoe Posted September 29, 2007 Share Posted September 29, 2007 if($ref == "http://www.sitename.com/post1.php" || $ref == "http://www.sitename.com/post2.php"){ //enter page }else{ echo "Invalid Request"; } if($ref != "http://www.sitename.com/post1.php" && $ref != "http://www.sitename.com/post2.php"){ echo "Invalid Request"; }else{ //enter page } Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357752 Share on other sites More sharing options...
btherl Posted September 29, 2007 Share Posted September 29, 2007 I tried this and it didn't work. If ($ref != 'http://www.sitename.com/page1.php' || $ref != 'http://www.sitename.com/page2.php') { echo Looks like the array solution only evaluates one value unless I'm incorrect here. markjoe has got it .. not goes with and, and equals goes with or in this case. Regarding the array solution, have you tried it? It works with any number of values. Every value in the array is checked. The logic is inverted though - you are checking for equals rather than not equals. It's the same logic as markjoe's first example. Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357883 Share on other sites More sharing options...
Barand Posted September 29, 2007 Share Posted September 29, 2007 Boolean logic NOT (A OR B) == NOT A AND NOT B if A != B (NOT A OR NOT B) will allow any value Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357896 Share on other sites More sharing options...
The Little Guy Posted September 29, 2007 Share Posted September 29, 2007 <?php $ref = $_SERVER['HTTP_REFERER']; If ($ref != "http://www.sitename.com/post1.php" || $ref != "http://www.sitename.com/post2.php") { echo "<head><title>Invalid Request</title></head>"; echo "This operation cannot be performed. Please go to <a href=\"http://www.sitename.com\">www.carolynkedesigns.com</a> to order. </font>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71130-using-logical-operator-with-an-if/#findComment-357988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.