1.Auth类文件引入

2.写一个公共类AuthInfo,所有要权限认证的类都继承此公共类AuthInfo

class AuthInfo extends Controller{
  protected function _initialize(){
    if(!session("?intel_uid")){
      echo "<script>alert('没有登陆!');window.location.href = '".url('index/index/index')."';</script>";
    }
    $uid = session('intel_uid');
    if($uid==1){
      return true;
    }
    $userArr=db('in_user')->where('id='.$uid)->find();
    $access_id = $userArr['role'];
    $auth = new Auth();
    $name=request()->module().'/'.request()->controller().'/'.request()->action();
    if(!$auth->check($name,$access_id)){
      $this->error('没有权限!');
    }
  }
}

thinkphp5_auth 权限认证

相关文章:

  • 2021-08-05
  • 2021-07-08
  • 2021-10-14
  • 2022-01-13
  • 2021-12-04
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2022-12-23
  • 2021-11-03
  • 2021-08-12
  • 2021-05-25
相关资源
相似解决方案