search
Homephp教程php手册Auth认证类通用认证代码

使用Auth.class.php对系统进行认证,其中频繁用到认证,在前面的基础上做了改进。
登陆成功后,将当前用户的id存入:session('uid',$curUserId);
在Config.php中配置:'NOT_AUTH_MODULE'        =>'Public,Index,Test',    // 默认无需认证模块<br>     'NOT_AUTH_ACTION'        =>'',        // 默认无需认证操作<br>     'SUPERADMIN_UID'=>array(1,2),function authcheck($url,$relation='or'){<br> <br>     $linkArr=explode('/',$url);<br>     if(!(count($linkArr)==2||count($linkArr)==3))return;<br>                     <br>     if(count($linkArr)==2){<br>         $CUR_MODULE_NAME=$linkArr[0];<br>         $CUR_ACTION_NAME=$linkArr[1];<br>     }else{<br>         $CUR_MODULE_NAME=$linkArr[1];<br>         $CUR_ACTION_NAME=$linkArr[2];<br>     }        <br>     $notAuth=in_array($CUR_MODULE_NAME, explode(",", C("NOT_AUTH_MODULE"))) || in_array($CUR_ACTION_NAME, explode(",", C("NOT_AUTH_ACTION")));<br>         <br>     $AUTH_CONFIG=C('AUTH_CONFIG');<br>     if(!$AUTH_CONFIG['AUTH_ON']||$notAuth)return true;<br>     else{<br>         if(!session("?uid"))return false;<br> <br>         if(in_array(session('uid'),C('SUPERADMIN_UID')))return true;<br>         else{<br>             import('ORG.Util.Auth');<br>             $auth=new Auth();<br>             if($auth->check($CUR_MODULE_NAME.'/'.$CUR_ACTION_NAME,session('uid'),$relation))return true;<br>             else return false;<br>         }<br>     }<br> }所有的Action均需要继承CommonAction.class.php,在Common的 _initialize()方法中使用:if(!authcheck(MODULE_NAME.'/'.ACTION_NAME))$this->error('你没有权限',U('Index/index'));在后台中对think_auth_rule数据表中在name字段存入操作的url,如:User/index,User/addRecord......

有不明白的地方有问必答,欢迎大家探讨。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor