我已经在页面上生成了一个变量,然后想要在位置重定向的末尾输出它,我已经通过回显它并将它放入浏览器来检查sendlink并且所有似乎都是正确的,不知道为什么这样做没有工作
$sendlink = "landing.php?destination1=" . $destination1 . "&destination2=" . $destination2 . "";
if($destination1 & $destination2 != ""){
header( "Location: /" . $sendlink );
}
答案 0 :(得分:3)
看到所有其他答案弹出......
首先,您在条件语句中错过了&符号。
if($destination1 & $destination2 != "")
^ missing an ampersand here
应该有两个,你还需要对两个变量使用相同的逻辑。
if($destination1 != "" && $destination2 != "")
或同时使用条件empty()
。
即:!empty()
。 !
运算符代表" not"空。
参考文献:
另一件事;最好在标题后添加exit;
,如果你有更多的代码。否则,它可能希望继续执行脚本的其余部分。
参考:
确保您在标头之前没有输出。
如果您收到标题发送通知,请参阅以下内容:
答案 1 :(得分:2)
为实现这一目标,有很多方法。
方法1 !empty()
:
if((!empty($destination1)) && (!empty($destination2))) {
header( "Location: /" . $sendlink );
}
方法2 isset()
(未设置):
if((isset($destination1)) && (isset($destination2))) {
header( "Location: /" . $sendlink );
}
方法3 !==''
:
if(($destination1 !== '') && ($destination2 !== '')) {
header( "Location: /" . $sendlink );
}
答案 2 :(得分:0)
提供者:Fred -ii-
if($destination1 != "" && $destination2 != "")
或使用empty()