Jump to content

PHP 'or' operator


Boerboel649

Recommended Posts

This ought to be a simple question... 

 

I have a page which has the following PHP code:

<?php
if ($_SERVER['HTTP_REFERER'] != 'URLremoved')
     header("Location:/rostercpanel/login.php ");
?>

 

Now, what I want to do, is add some other URL's, that are authorized URL's to come from.  I've tried the 'or' and the '||' operators, but I have a feeling I'm doing it wrongly.  Could someone please give me the code for this?

 

If I didn't make myself clear enought let me know and I'll go into more detail.

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/47137-php-or-operator/
Share on other sites

I think your problem is that you are using a does not equal operator. If you have two or more negative conditions using OR then one of them will always fail (when testing the same property)

 

Ex:

if ($url != "url1" OR $url != "url2") 

 

That will ALWAYS fail because even if the value does equal one of the tests it won't equal the 2nd.

 

You need to use the AND condition

 

<?php
if ($_SERVER['HTTP_REFERER'] != 'URL1' AND $_SERVER['HTTP_REFERER'] != 'URL2')
    header("Location:/rostercpanel/login.php ");
?>

Link to comment
https://forums.phpfreaks.com/topic/47137-php-or-operator/#findComment-229867
Share on other sites

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.