Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn how to use Auth. class. php to authenticate the system. authentication is frequently used, and improvements have been made on the basis of the above.
After successful login, save the current user's id to session ('uid', $ curUserId );
Configure in Config. php:
'Not _ AUTH_MODULE '=> 'public, Index, test', // no authentication module is required by default.
'Not _ AUTH_ACTION '=> '', // no authentication is required by default.
'Superadmin _ uid' => array (1, 2 ),
function authcheck($url,$relation='or'){
$linkArr=explode('/',$url);
if(!(count($linkArr)==2||count($linkArr)==3))return;
if(count($linkArr)==2){
$CUR_MODULE_NAME=$linkArr[0];
$CUR_ACTION_NAME=$linkArr[1];
}else{
$CUR_MODULE_NAME=$linkArr[1];
$CUR_ACTION_NAME=$linkArr[2];
}
$notAuth=in_array($CUR_MODULE_NAME, explode(",", C("NOT_AUTH_MODULE"))) || in_array($CUR_ACTION_NAME, explode(",", C("NOT_AUTH_ACTION")));
$AUTH_CONFIG=C('AUTH_CONFIG');
if(!$AUTH_CONFIG['AUTH_ON']||$notAuth)return true;
else{
if(!session("?uid"))return false;
if(in_array(session('uid'),C('SUPERADMIN_UID')))return true;
else{
import('ORG.Util.Auth');
$auth=new Auth();
if($auth->check($CUR_MODULE_NAME.'/'.$CUR_ACTION_NAME,session('uid'),$relation))return true;
else return false;
}
}
}
All actions must inherit CommonAction. class. php and be used in the _ initialize () method of Common:
If (! Authcheck (MODULE_NAME. '/'. ACTION_NAME) $ this-> error ('You have no authorization', U ('index/Index '));
In the background, store the name field in the think_auth_rule data table to the operation url, for example, User/index, User/addRecord ......
If you have any questions, you are welcome to discuss them.
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB