vendredi 25 septembre 2020

(php) what's wrong with the conditional operator? there's a function that founds if an associative array have any key

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?

Aucun commentaire:

Enregistrer un commentaire