If with $ _SESSION

2
if(!isset($_SESSION["TIP"])){
    header("location:../index.php?msg=1");
}else if(isset($_SESSION["TIP"])){
    if($_SESSION["TIP"]!="Normal"){
        header("location:../index.php?msg=3");  
    }else if ($_SESSION["TIP"]!="Gold") {
        header("location:../index.php?msg=3");                  
    }
}

I have this code to validate if the user who enters the program has the corresponding permissions, the problem is that my variable $_SESSION["TIP"] if it is equal to "Normal" but I take it as if it were not.

This only happens when I put the else if or about || in the condition, does anyone know where my error is?

    
asked by martinfcamposc 13.12.2018 в 06:54
source

4 answers

1

Good to the point, you say that $ _SESSION ["TIP"] if it is equal to "Normal". But you never tell him what he would do if he did. Your code only has comparisons in case it is different from "normal" and "gold".

    
answered by 13.12.2018 в 07:11
0

At no time do you define the action that you would take if $_SESSION["TIP"] == "Normal" .

One solution would be to define it in the following way:

if(!isset($_SESSION["TIP"])){
    // Variable de sesión no establecida

} else {
    if( $_SESSION["TIP"] == "Normal" ){
        // Establecida, es Normal

    } else if ( $_SESSION["TIP"] == "Gold") {
        // Establecida, es Gold 

    } else {
        // Establecida, pero no es ninguna de las anteriores

    }
}

I hope this is what you are looking for!

    
answered by 13.12.2018 в 07:20
0

The solution was easier than it seemed:

if(!isset($_SESSION["TIP"])){
    header("location:../index.php?msg=1");
}else if(isset($_SESSION["TIP"])){
    if($_SESSION["TIP"]!="Normal" && $_SESSION["TIP"]!="Gold"){
        header("location:../index.php?msg=3");
    }               
}

I just had to change the || by & & amp; amp; amp;

    
answered by 13.12.2018 в 14:47
0

It's simple as:

$session = $_SESSION["TIP"] ?? false;
if(!$session){
   header("location:../index.php?msg=3"); 
}

if ($session != "Gold" || $session != "Normal" ) {
   header("location:../index.php?msg=3");                  
}



// continuamos ejecucion normal  porque es gold o normal
    
answered by 13.12.2018 в 15:29