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?
– Daniel Mendes
The console is your best friend! D
– Daniel Mendes
Have you tried debugging and viewing content, using a var_dump on
$_SESSION["tipo"]
?– Daniel Mendes
I haven’t tried yet, how can I do with var_dump?
– Matheus
https://www.php.net/manual/en/function.var-dump.php
– Daniel Mendes
There should be several examples here on the site, search like this: https://answall.com/search?q=var_dump+%5Bphp%5D
– Daniel Mendes
I did so but it was an error: $test = if($_SESSION["type"] != '1'){ var_dump($test);
– Matheus
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.
– André Martins
is that I used if method, so it did not work..
– Matheus
An example: https://repl.it/repls/WindingMediumorchidPhysics
– Daniel Mendes
The strange thing is that passing to mine here, nothing appears on the console, and the application does not work...
– Matheus