Home > Backend Development > PHP Tutorial > 分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目,该如何处理

分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目,该如何处理

WBOY
Release: 2016-06-13 13:28:23
Original
801 people have browsed it

分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目


user表就是用户表了,可以存储上万条的用户也没关系,后面的groupid 为1 就是管理员权限,为2就是游客权限



model表存储框架的各个方法名,后面的group是set集合类型,代表哪个组拥有这个权限

废话不多说,看例子代码

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php class IndexAction extends YouYaX
{
        public function index()
        {
            header("Content-type: text/html; charset=utf-8");
            //登陆的步骤省略
            $user="我是游客";
            //$user="我是管理员";
            $data=$this->find("user","string","user='".$user."'");
            $group_tmp=$data["groupid"];            
            $this->show($group_tmp);
         }
         public function show($group_tmp){
             $list=$this->find("model","string","func='show'");
             $sql="select * from model where func='show' and find_in_set(".$group_tmp.",".$list['group'].")";     
             if(mysql_num_rows(mysql_query($sql))){
                 echo "权限通过";
                 //处理下面的内容
             }else{
                 echo "没有权限";
             }
         }
         public function showAll($group_tmp){
             $list=$this->find("model","string","func='showAll'");
             $sql="select * from model where func='showAll' and find_in_set(".$group_tmp.",".$list['group'].")";     
              if(mysql_num_rows(mysql_query($sql))){
                 echo "权限通过";
                 //处理下面的内容
             }else{
                 echo "没有权限";
             }
         }
}
?>
Copy after login




欢迎参考。。。

------解决方案--------------------
model表需要加上model名,不然无法区分不同model的同名方法
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template