Jump to content

Adding and OR statement


thefonz22

Recommended Posts

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

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}

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"); }

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.