I have an application where there are two types of users (manager and technician), when a user loguea depends on the type that will be a menu or another, when the user is logged in when he clicks on the header I want him to take to its corresponding menu.
In the if statement that I put below, it does not do the if right, it jumps to the else always, and it is in a user manager or a technical user.
<?php
session_start();
if (isset($_SESSION['numero_empleado'])) {
header('Location: Login');
}
require 'conexion.php';
$records = $conexion->prepare('SELECT numero_empleado, email, cargo, password FROM usuarios WHERE email=:email');
$records->bindParam(':email', $_POST['email']);
$records->execute();
$resultados = $records->fetch(PDO::FETCH_ASSOC);
$_SESSION['numero_empleado'] = $resultados['numero_empleado'];
if ($resultados['cargo'] === 'manager') {
header('Location: ../Menus/menu_manager.php');
} else {
header('Location: ../Menus/menu_tecnico.php');
}
?>
Sorry for the way I put the code, but I'm new and I still do not know how to put things.
LOGIN CODE
<?php
session_start();
if (isset($_SESSION['numero_empleado'])) {
header('Location: Login');
}
require 'conexion.php';
if (!empty($_POST['email']) && !empty($_POST['password'])){
$records = $conexion->prepare('SELECT numero_empleado, email, cargo, password FROM usuarios WHERE email=:email');
$records->bindParam(':email', $_POST['email']);
$records->execute();
$resultados = $records->fetch(PDO::FETCH_ASSOC);
$message = '';
if (count($resultados) > 0 && password_verify($_POST['password'], $resultados['password'])){
$_SESSION['numero_empleado'] = $resultados['numero_empleado'];
if ($resultados['cargo'] === 'manager') {
header('Location: ../Menus/menu_manager.php');
} else {
header('Location: ../Menus/menu_tecnico.php');
}
}else {
$message = 'La contraseña es incorrecta';
}
}
?>
Login
<?php require 'partials/header.php'; ?>
<h1>Login</h1>
<span> o <a href="registrarse.php">Registrarse</a></span>
<?php if (!empty($message)): ?>
<p><?=$message?></p>
<?php endif; ?>
<form action="login.php" method="post">
<input type="text" name="email" placeholder="Pon tu correo">
<input type="password" name="password" placeholder="Ingresa una contraseña">
<input type="submit" value="Enviar">
</form>
</body>