Good, I have an archiv that retrieves the IDs and makes a login for roles so that:
VALIDAR.PHP
<?php
//Fichero que usara para mandar los datos recibidos más abajo para pasarlos por el controlador.
include "../controlador/usuariosControlador.php";
//Recoge los datos de index.php introducidos en el login, verifica que en ambos campos existan datos.
if (isset($_POST["usuario"]) || isset($_POST["pass"])) {
if (trim($_POST["usuario"]) == "" || trim($_POST["pass"]) == "") {
echo "false";
} else {
$usuariosCon = new usuariosControlador();
$usuario = $usuariosCon->validar($_POST["usuario"], $_POST["pass"]);
if (count($usuario) > 0) {
//Una vez detecta que el usuario existe le indicaremos los datos que debe seguri la SESSION para calificar los roles, es decir, hacia donde debe de dirigir todo el trafigo del log segun su rol.
session_start();
$_SESSION["id"] = $usuario["id"];
$_SESSION["usuario"] = $usuario["usuario"];
$_SESSION["privilegio"] = $usuario["privilegio"];
echo "true";
echo $validacion;
if ($_SESSION['privilegio'] == 0) {
header('location: userinv.php');
} else if ($_SESSION['privilegio'] == 1) {
header('location: user.php');
} else if ($_SESSION['privilegio'] == 2) {
header('location: jefe.php');
} else if ($_SESSION['privilegio'] == 3) {
header('location: administrador.php');
} else if ($_SESSION['privilegio'] == 4){
header('location: superadmin.php');
}
else {
echo "false";
}
}
}
}
?>
As we see, it redirects the websites that I tell you, and within this one you have options to move around. Well, if you enter one of these, it goes like this:
Menuadmin.php
session_start();
//Iniciaremos la variable SESSION y con ello le indicaremos QUIÉN NO tiene permisos para acceder aqui
if (!isset($_SESSION["privilegio"]) || $_SESSION["privilegio"] == 0) {
print "<script>alert(\"Acceso invalido!\");window.location='../../index.php';</script>";
}
if (!isset($_SESSION["privilegio"]) || $_SESSION["privilegio"] == 1) {
print "<script>alert(\"Acceso invalido!\");window.location='../../index.php';</script>";
}
if (!isset($_SESSION["privilegio"]) || $_SESSION["privilegio"] == 2) {
print "<script>alert(\"Acceso invalido!\");window.location='../../index.php';</script>";
}
To check that you have permission to access or not. Well once you access this you want to go to your main menu but I can not because the data of your session is as if you have already lost them, nose,
For example, I said, go back to the validar.php file to redirect it to your predefined index but the page remains blank:
<?php echo '<a href="../../validar.php">Menu</a>'; ?></li>