php 人员权限管理(RBAC)实例(推荐)(2)

<?php require "../DBDA.class.php"; $db = new DBDA(); $uid = $_POST["uid"]; $js = $_POST["js"]; //清空原有角色 $sql = "delete from userinjuese where userid='{$uid}'"; $db->query($sql); //添加选中的角色 $ajs = explode(",",$js); foreach($ajs as $v) { $sql = "insert into userinjuese values('','{$uid}','{$v}')"; $db->query($sql); }

二.完成管理员页面后,下面就是登录页面

1.登录基本页面 login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <h1>登录界面</h1> <form action="dlchuli.php" method="post"> <div>用户名:<input type="text" /></div> <div>密码: <input type="password" /></div> <input type="submit" value="登录" /> </form> </body> </html>

2.登录处理的页面 dlchuli.php

<?php session_start(); require "../DBDA.class.php"; $db = new DBDA(); $uid = $_POST["uid"]; $pwd = $_POST["pwd"]; $sql = "select pwd from users where uid='{$uid}'"; $mm = $db->strquery($sql); if($mm==$pwd && !empty($pwd)) { $_SESSION["uid"] = $uid; header("location:main.php"); } else { echo"输入的用户名或密码有误!"; }

3.主页面 main.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> .list{ width:100px; height:35px; border:1px solid #36F; margin:0px 2px 0px 2px; text-align:center; vertical-align:middle; line-height:35px;} </style> </head> <body> <h1>主页面</h1> <?php session_start(); $uid =""; if(empty($_SESSION["uid"]))<code>//判断session是否为空</code> { header("location:login.php");<code>//空的话就返回登录页面</code> exit; } $uid = $_SESSION["uid"]; require"../DBDA.class.php"; $db = new DBDA(); $sql = "select * from rules where code in(select distinct ruleid from juesewithrules where jueseid in(select jueseid from userinjuese where userid='{$uid}'))"; $arr = $db->query($sql,1); foreach($arr as $v) { echo "<div code='{$v[0]}'>{$v[1]}</div>"; } ?> </body> </html>

选择登陆张三显示他的权限,效果如下:

以上这篇php 人员权限管理(RBAC)实例(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/338cafc4ddbe2b2c2ec34547ed05fbde.html