• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 4年前 (2022-01-23) 12次浏览 已收录 0个评论

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

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

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

废话不多说,看例子代码

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpclass 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<em style="color:transparent">本文来源gao.dai.ma.com搞@代*码#网</em><a>搞代gaodaima码</a>' and find_in_set(".$group_tmp.",".$list['group'].")";                   if(mysql_num_rows(mysql_query($sql))){                 echo "权限通过";                 //处理下面的内容             }else{                 echo "没有权限";             }         }}?>

欢迎参考。。。

——解决方案——————–
model表需要加上model名,不然无法区分不同model的同名方法


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目,该如何处理
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址