Problems with comparison operators

Asked

Viewed 45 times

0

I am developing a site, and it has levels of login access, being "1" == "Student", "2" == "Teacher" and so on...

I tried to make a system so that if the user is not logged in email and password, he does not enter the page, but I want to make it also check if the type of user is compatible with the page he is entering.

<?php 
  session_start(); 
  if(!isset($_SESSION["email"]) || !isset($_SESSION["senha"])) { 
    if($_SESSION["tipo"] != '1'){
      // Usuário não logado! Redireciona para a página de login 
      header("Location: index.php?login"); 
      exit; 
    }
  }
?>

But he’s not checking:

if($_SESSION["tipo"] != '1'){

How can I make the operator work? NOTE: This operator has to be checked in the mysql table.

  • Did you check if type is set, display its value on the console, something like that?

  • The console is your best friend! D

  • Have you tried debugging and viewing content, using a var_dump on $_SESSION["tipo"]?

  • I haven’t tried yet, how can I do with var_dump?

  • https://www.php.net/manual/en/function.var-dump.php

  • There should be several examples here on the site, search like this: https://answall.com/search?q=var_dump+%5Bphp%5D

  • I did so but it was an error: $test = if($_SESSION["type"] != '1'){ var_dump($test);

  • it goes in my tip, if you do not know how to debug learn that it will save you many hours of headache, even so if you do not want to learn or do not have time, it will print everything on the console.

  • is that I used if method, so it did not work..

  • An example: https://repl.it/repls/WindingMediumorchidPhysics

  • The strange thing is that passing to mine here, nothing appears on the console, and the application does not work...

Show 6 more comments

1 answer

0


if((empty($_SESSION['email'])) || (empty($_SESSION['senha'])) || (empty($_SESSION['tipo']))){       
  header("Location: index.php");
}else{
  if($_SESSION['tipo'] != "1"){
      header("Location: index.php");
  }
}

To resolve I had to do as follows above:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.