如何根据用户权限进行回显

时间:2019-04-23 20:01:00

标签: php mysqli

我正在尝试构建一个访问级别系统,其中管理员看到x,主管看到y,用户看到z(不是实际角色)。

以前没有构建访问级别系统,但是已经考虑过使用类似下面的方法,但是它不起作用:

if(isset($_SESSION['Usertype'])){

  if($_SESSION['Usertype'] == "admin"){
   echo "You are an admin";
   }
   else {
     echo "You are not an admin";
   }
}

甚至是这个:

if(isset($_SESSION['Usertype'])){

  if($_SESSION['Usertype'] == "admin"){
   echo "You are an admin";
   }
  if($_SESSION['Usertype'] == "supervisor"){
   echo "You are a supervisor";
   }
  if($_SESSION['Usertype'] == "user"){
   echo "You are a user";
   }
}

1 个答案:

答案 0 :(得分:0)

这对我有用。

session_start();
$_SESSION['Usertype'] = 'admin';
echo $_SESSION['Usertype'];
if(isset($_SESSION['Usertype'])){
  if($_SESSION['Usertype'] == "admin"){
   echo "You are an admin";
  }
  if($_SESSION['Usertype'] == "supervisor"){
   echo "You are a supervisor";
  }
  if($_SESSION['Usertype'] == "user"){
   echo "You are a user";
  }
}