How to compare different arrays of the $ _session

0

I'm trying to make a comparison after session_start();

What I was thinking and trying to do is:

<?php
  session_start();
    if($_SESSION['id_usuario']=NULL) {
       $_SESSION['id_nivel']=3;
           if($_SESSION['id_usuario']= 'X') {
          }
      }
   else {
     header("Location: register.php");
   }
?>

Is there a possibility to do it? Any help to achieve it?

    
asked by Juan 02.02.2018 в 17:33
source

1 answer

1

When you compare values in a condition is done with == or === , what you are doing is an assignment simply with = , then your code should be.

Now if you want to validate that the user exists, you could do it with isset directly on the $_SESSION['id_usuario']

<?php
  session_start();
    if($_SESSION['id_usuario']=== NULL) {
       $_SESSION['id_nivel']=3;//asignas a 3
           if(isset($_SESSION['id_usuario']) {//Si está definido el id_usuario
             // $iduser = $_SESSION['id_usuario'];
             // $con = "SELECT * FROM usuarios WHERE id_usuario = $iduser;
             // Agregue estos comentarios con posibilidad de hacer una consulta y traer
             // los datos existentes a "X". Pero nose si esto seria lo correcto.
          }
      }
   else {
     header("Location: register.php");
   }
?>
    
answered by 02.02.2018 / 17:41
source