我想在定义超级全局变量$ _GET [“ chapter”]且没有我未指定的值时重定向用户:
if(isset($_GET["chapter"])){
$myChapter=$_GET["chapter"];
if($myChapter!="prelude" OR $myChapter!="chapter-1"){
header("location:what.php");
}
}
当我设置超级全局变量$ _GET [“ chapter”]时,就会出现问题,它被定义为前奏或链接中的第1章
chapter=prelude
该页面将我重定向到what.php(错误页面)。如果仅使用一个条件修改条件,则重定向功能(标题)不会将我重定向到what.php。有用
if(isset($_GET["chapter"])){
$myChapter=$_GET["chapter"];
if($myChapter!="prelude"){
header("location:what.php");
}
}
如果放置一个“否则”或另一个“如果”,则有条件的条件起作用。
最后一个问题:有一个函数可以找到关联数组是否有键吗?
您拥有的条件将始终返回true。如果$myChapter
是prelude
,则等于chapter-1
。看来您打算使用and
逻辑运算符,而不是or
:
if ($myChapter != "prelude" and $myChapter != "chapter-1") {
// Here ----------------^
header("location:what.php");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句