Home  >  Article  >  php教程  >  thinkphp教程之RBAC详解4之权限校验

thinkphp教程之RBAC详解4之权限校验

WBOY
WBOYOriginal
2016-06-07 11:44:361484browse

权限校验部分
新建CommonAction类文件,写入以下代码<?php <br /> class CommonAction extends Action{<br> //初始化方法,调用方法时会先执行<br> function _initialize(){<br>     header('Content-Type:text/html;charset=utf-8');<br>         import('ORG.Util.Cookie');<br>         // 用户权限检查<br>         if (C('USER_AUTH_ON') && !in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE')))) {<br>             import('ORG.Util.RBAC');<br>             if (!RBAC::AccessDecision()) {<br>                 //检查认证识别号<br>                 if (!$_SESSION [C('USER_AUTH_KEY')]) {<br>                     //跳转到认证网关<br>                     redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));<br>                 }else{<br>                     echo L('_VALID_ACCESS_');<br>                     exit();<br>                 }<br>                 // 没有权限 抛出错误<br>                 if (C('RBAC_ERROR_PAGE')) {<br>                     // 定义权限错误页面<br>                     redirect(C('RBAC_ERROR_PAGE'));<br>                 } else {<br>                     if (C('GUEST_AUTH_ON')) {<br>                         $this->assign('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY'));<br>                     }<br>                     // 提示错误信息<br>                     $this->error(L('_VALID_ACCESS_'));<br>                 }<br>             }<br>         }<br> }到此RBAC权限判断就基本完成,是不是没有想象中那么难?如果看完这几篇文章还是不明白,欢迎加我QQ544828662咨询。

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn