Block pages by access level

Asked

Viewed 70 times

0

Hello... I am with a project where when the user logs in he must have access to only a few pages, in the bank I have a column "Level" that is the level of access, I am trying to make the verification, but without success, follow code, always redirects to page when only finds an admin, but would like to check if the logged in user is admin

<?php require_once("conecta/conexao.php");?>
<?php 
session_start(); 

//Restringir a pagina
$conta = "SELECT * ";
$conta.= "FROM usuarios ";
$conta.= "WHERE nivel='admin'";
$conta = mysqli_query($conecta, $conta);

$validar = 0;
if(mysqli_num_rows($conta) > 0){
    $validar = 1;
    $mensagem = "Olá  ".$_SESSION["user_portal"]." tudo bem? Quem vamos cadastrar hoje?";
}else{
    header("location:index.php");
}
?>
  • You must inform the user. The code SQL that you are using will always return a record if there is at least one administrator. What you have to do is something like: SELECT * FROM usuarios WHERE username = "NOME-DO-USUARIO" AND nivel = "admin";. This way it checks whether or not a particular user has the recommended access level.

  • <?php require_once("connects/connected.php");? > <? php session_start(); //Restrict page $nivel = "SELECT * FROM usuarios WHERE usuario='Diego' AND nivel='admin'"; $nivel = mysqli_query($conecta, $nivel); if($nivel == "Diego"){ $message = "Hello". $_SESSION["user_portal"]." All right? Who do we register today?" ; }Else{ header("Location:index.php"); } ? > To no avail

No answers

Browser other questions tagged

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