php是否或如何?
我试图用OR做if语句,但它不起作用php是否或如何?,php,logical-operators,Php,Logical Operators,我试图用OR做if语句,但它不起作用 $ref = $_SERVER['HTTP_REFERER']; $refData = parse_url($ref); if($refData['host'] !== 'website1.com','website2.com') { die("..."); }else{ <content> } 谢谢大家替换==到=并根据需要使用&或或=| $ref = $_SERVER['HTTP_REFE
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
if($refData['host'] !== 'website1.com','website2.com') {
die("...");
}else{
<content>
}
谢谢大家替换
==代码>到=编码>并根据需要使用&
或或=|
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
if($refData['host'] != 'website1.com' || $refData['host'] != 'website2.com') {
die("...");
}else{
echo 'hi testing';
//run your php code here
}
您的问题是,您正在检查两者是否不相同
`!=` ( Not equal)
`!==` (Not identical)
&& example $x && $y True if both $x and $y are true
|| example $x || $y True if either $x or $y is true
是PHP中的OR运算符
但是在这里,您需要AND运算符&&
像这样:
if($refData['host'] !== 'website1.com' && $refData['host'] !== 'website2.com')
考虑在数组中使用
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
$array_data = ["website1.com","website2.com"];
if(in_array($refData, $array_data))
{
echo "Do Something!";
}
else
{
echo "Failed!";
}
你的逻辑是无效的。不要使用或而是使用&&
@u\u mulder看起来像答案。为什么要写在评论里?可能需要一些代码和一些额外的解释。这根本不起作用,没有错误,只返回“…”replace或to|
我会修复您返回的标签名为
这是什么意思?你想输出一些var或其他东西吗?没有内容只是一些php代码从db获取一些东西并回显它。如果一切正常,我会替换代码。现在应该在浏览器中输出‘hi testing’
||
if($refData['host'] !== 'website1.com' && $refData['host'] !== 'website2.com')
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
$array_data = ["website1.com","website2.com"];
if(in_array($refData, $array_data))
{
echo "Do Something!";
}
else
{
echo "Failed!";
}