thefonz22 Posted May 1, 2013 Share Posted May 1, 2013 Simple question, I want to add an OR statement to the example below. I can't remember what the syntax is. if($ref !== 'http://www.example.com/prestige/') { die("Hotlinking not permitted"); } echo "Successful Login!"; Why wont this work? This is how I'm trying to do my OR statement with 2 URL's. if($ref !== 'http://www.example.com/prestige/') || ($ref !== 'http://www.example2.com/prestige/') { die("Hotlinking not permitted"); } echo "Successful Login!"; Please help! Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/277502-adding-and-or-statement/ Share on other sites More sharing options...
litebearer Posted May 1, 2013 Share Posted May 1, 2013 If you use OR the test will fail - ie if one is good and one is bad, OR both are bad , it will produce fail If you use AND then both conditions must be bad for it to produce fail Soooo. if($a !== $b AND $a !== $c) {then do something }else{do something else} Link to comment https://forums.phpfreaks.com/topic/277502-adding-and-or-statement/#findComment-1427566 Share on other sites More sharing options...
lemmin Posted May 1, 2013 Share Posted May 1, 2013 All the conditions should be wrapped inside the same set of parentheses: if($ref !== 'http://www.example.com/prestige/' || $ref !== 'http://www.example2.com/prestige/') { die("Hotlinking not permitted"); } HOWEVER, since you are negating both sides of the OR, this statement will ALWAYS evaluate to false. So, as litebearer suggested, you want to change to and AND: if($ref !== 'http://www.example.com/prestige/' && $ref !== 'http://www.example2.com/prestige/') { die("Hotlinking not permitted"); } Link to comment https://forums.phpfreaks.com/topic/277502-adding-and-or-statement/#findComment-1427567 Share on other sites More sharing options...
thefonz22 Posted May 1, 2013 Author Share Posted May 1, 2013 If you use OR the test will fail - ie if one is good and one is bad, OR both are bad , it will produce fail If you use AND then both conditions must be bad for it to produce fail Soooo. if($a !== $b AND $a !== $c) {then do something }else{do something else} Thanks! Worked a treat. Link to comment https://forums.phpfreaks.com/topic/277502-adding-and-or-statement/#findComment-1427569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.