Permission Validation - PHP

Asked

Viewed 33 times

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

  1. Admin
  2. Manager
  3. T.I
  4. 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.

  • @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" } }

  • Ah, you used the fetchAll, he returns a array, then I would be $resultado[0]['acesso']

  • @Andersoncarloswoss worked out!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.