0
Good morning, I am developing a site for my TCC, and in it I try to make a login system with validation of user by levels.
Let’s assume if the user is administrator, when logging in he will check in the bd if the logged in user will have the field "type" != 2; if not it will go to normal user screen.
Below is the code I developed in php, but is showing error after trying to validate, it goes to a blank page;
<?php
include("conexao.php");
$email = $_POST['email'];
$senha = $_POST['senha'];
/* Verifica se existe usuario, o segredo ta aqui quando ele procupa uma
linha q contenha o login e a senha digitada */
$sql_logar = "SELECT * FROM aluno WHERE email = '$email' && senha = '$senha'";
$exe_logar = mysqli_query($conection, $sql_logar) or die (mysqli_error());
$fet_logar = mysqli_fetch_assoc($exe_logar);
$num_logar = mysqli_num_rows($exe_logar);
//Verifica se n existe uma linha com o login e a senha digitado
if ($num_logar == 0){
session_start();
$_SESSION['msg'] = "<div class='alert alert-danger'>Login ou senha incorreto!</div>";
header("Location: index.php?login");
}
else{
//Cria a sessão e verifica tipo de login
session_start();
while($percorrer = mysqli_fetch_array($exe_logar) ){
$tipo = $percorrer['tipo'];
if($_SESSION['tipo'] != 2){
$_SESSION['email'] = $email;
$_SESSION['senha'] = $senha;
header("Location: aluno.php");
}
}
}
?>
What can I do to make level validation work as planned?
Worse than not, it goes to valida.php which is the code above
– Matheus
The
session_start();
has to come first, before HTML even, if you have.– Sam
I separated valida.php from the html form with an action="valida.php", but I also need to put Session start before in php?
– Matheus
You’re gonna put the
sessiont_start();
only once after opening<?php
. And also don’t use&&
. UseAND
.– Sam
I did what you asked, but it still didn’t work, returned to valida.php, I think the problem is in while.
– Matheus
But not anymore? Buguei kkkkkkk
– Matheus
It worked, but when it is equal to 2 it does not go to the administrator.php, I would use Else there?
– Matheus