0
I have a problem in implementing the validation of a page, because it is always allowing the user to access the page regardless of the type of access, could help me?
Types of Access
- Admin
- Manager
- T.I
- Collaborator
database
Tabela Usuário:
Id: 1
Nome: Bruno
Senha: 123
Permissão: 1
session_start();
//Verifica se o usuário esta logado
$nome = $_SESSION['nome'];
if(!isset($nome)){
header("location: ../index.php");
}
include_once ('../public/setting/conexaoBanco.php');
$mensagem = "";
$verificaPermissao = $conectarBanco->prepare("SELECT acesso FROM user where nome = '$nome'");
$verificaPermissao->execute();
$resultado = $verificaPermissao->fetchAll(PDO::FETCH_ASSOC);
// dados do resultado = array(1) { [0]=> array(1) { ["acesso"]=> string(1) "4" } }
if($resultado > 1){
header("location: restrito.php");
}else{
$msg = "Seja bem vindo $_SESSION['nome']";
}
You shouldn’t check if
$resultado['acesso']
is greater than 1? It makes no sense to compare a array as a whole.– Woss
@Andersoncarloswoss then did so so that you explained how to validate the information of the $result array['access'] the same returns null and if I give a var_dump of $result only the same returns // result data = array(1) { [0]=> array(1) { ["access"]=> string(1) "4" } }
– Bruno Ferreira
Ah, you used the
fetchAll
, he returns a array, then I would be$resultado[0]['acesso']
– Woss
@Andersoncarloswoss worked out!
– Bruno Ferreira