I want to redirect the user when the super global variable $_GET["chapter"] it's defined and it does not have a value that I didn't specify:
if(isset($_GET["chapter"])){
$myChapter=$_GET["chapter"];
if($myChapter!="prelude" OR $myChapter!="chapter-1"){
header("location:what.php");
}
}
the problem happens when I set the super global variable $_GET["chapter"] it's defined as prelude or as chapter-1 in the link
chapter=prelude
the page redirect me to what.php (the error page). If I modify the conditional with a just one condition, the redirect function (header) does not redirect me to what.php. It works
if(isset($_GET["chapter"])){
$myChapter=$_GET["chapter"];
if($myChapter!="prelude"){
header("location:what.php");
}
}
if a put a "else if" or another "if" the conditional left to work.
Last question: there is function that found if an associative array have any key?
The condition you have will always return true. If, eg, $myChapter
is prelude
, it won't be equal to chapter-1
. It looks like you meant to use the and
logical operator, not or
:
if ($myChapter != "prelude" and $myChapter != "chapter-1") {
// Here ----------------^
header("location:what.php");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.