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
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}

Link to comment
Share on other sites

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
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}

Thanks! Worked a treat.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.