0
good afternoon i made a system, bd ok and loguin check ok however wanted after checking the user it open the right page for the user certain example: I have 3 levels being 0 1 2 and I want the user level 0 open the page index1.php the level user 1 open the page index2.php and the level user 2 open the page index3.php
<?php
session_start(); // Inicia a session
include "config.php";
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
if ((!$usuario) || (!$senha)){
echo "Por favor, todos campos devem ser preenchidos! <br /><br />";
include "index.html";
}else{
$senha = md5($senha);
$sql = mysql_query(
"SELECT * FROM xxxxxx_usuarios
WHERE usuario='{$usuario}'
AND senha='{$senha}'
AND ativado='1'"
);
$login_check = mysql_num_rows($sql);
if ($login_check > 0){
while ($row = mysql_fetch_array($sql)){
foreach ($row AS $key => $val){
$$key = stripslashes( $val );
}
$_SESSION['usuario_id'] = $usuario_id;
$_SESSION['nome'] = $nome;
$_SESSION['sobrenome'] = $sobrenome;
$_SESSION['email'] = $email;
$_SESSION['nivel_usuario'] = $nivel_usuario;
mysql_query(
"UPDATE xxxxx_usuarios SET data_ultimo_login = now()
WHERE usuario_id ='{$usuario_id}'"
);
header("Location: separador.php");
}
}else{
echo "Você não pode logar-se! Este usuário e/ou senha não são válidos!<br />Por favor tente novamente!<br />";
include "index.html";
}
}
?>
where when it executes the header("Location: separator.php") directs the open and validated user to its right page tried commands with if Else switch but Nunk get some idea.
this is the.php separator file
<?php
$nivel = $_SESSION['nivel_usuario'];
if ($nivel == 0){
header("location: /NORMAL/inicio.html");
} else if ($nivel == 1){
header("location: /PREMIUM/index.html");
} else if ($nivel == 2){
header("location: /ADM/index.html");
} else {
header("location: index.html");
}
?>
How do you know the user level? You are in the bank?
– user60252
Yes this in the bank discriminated
– Eduardo Saraiva
I was able to resolve relocating the code inside the verification page as proposed by @João Victor Souza... Personal upgrade
– Eduardo Saraiva
Now that we’ve seen your.php tab, it’s clear that session_start() is missing; at the beginning of the page
– user60252