简体   繁体   English

如果条件不适用于网址匹配,则为PHP

[英]PHP if condition doesn't work for urls matching

I am trying to match two URLs but it seems doesn't work. 我正在尝试匹配两个URL,但似乎不起作用。 I have tried works fine if I put manually. 如果我手动放置,我尝试的效果很好。

Here is the code: 这是代码:

$referby = $_SERVER['HTTP_REFERER'];
$link1="http://domain.com/admin/ajax/passcodev.php?order_id=".$orderid;
$link2="http://www.domain.com/admin/ajax/passcodev.php?order_id=".$orderid;

if($referby<>$link1 || $referby<>$link2)
 {
    header('Location:passcodev.php?order_id='.$orderid);
 }

I have no idea where I am doing mistake. 我不知道我在哪里做错。

if($referby<>$link1 || $referby<>$link2) means if $referby does not match $link1 or $link2 , proceed. if($referby<>$link1 || $referby<>$link2)表示如果$referby$link1 $link2不匹配,请继续。 Since it can't match both it always evaluates to true. 由于两者都无法匹配,因此总会得出true。

You need to use && (and): 您需要使用&& (和):

if($referby != $link1 && $referby != $link2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM