php personnel authority management (RBAC)

迷茫
Release: 2023-03-06 22:10:02
Original
1553 people have browsed it

Before talking about permission management, you should first know what functions permission management has:

 (1) Users can only access, specify Controller, specified method

 (2) Users can exist in multiple user groups

 (3) User groups You can choose the specified controller and the specified method

(4), you can add the controller and method

RBAC (Role-Based Access Control (role-based access control) is where users are associated with permissions through roles. Simply put, a user has several roles, and each role has several permissions. In this way, a "user-role-permission" authorization model is constructed. In this model, there is generally a many-to-many relationship between users and roles, and between roles and permissions.

1. Database design

Write five tables, first: user table, role table, function table:

Connection Table of tables.. Next is the role function table and user role table:

2. Administrator's Management page,

Query($sql); foreach ($arr as $v) { echo ""; } ?>
Copy after login

(1). Display user name and role name respectively

(2). According to the drop-down user name Change, change the role in the corresponding check box

(3). When modifying the user role, first delete the user's corresponding role table and all the information of this user, and then retrieve The username and role code are newly added.

Use the drop-down list: embed the php query and traverse it, display it in the form of a drop-down list

Select the role, use multiple Marquee:


请选择角色
$sjs = "select * from qxzw";
$ajs = $db->Query($sjs);
foreach ($ajs as $v){
echo "{$v[1]} ";
}?>



Copy after login

Picture:

##When the user changes, the corresponding role also changes accordingly, and the person's role information is changed and added and saved. The basic idea of adding and saving is to first delete all the role information corresponding to the person in the database, and then retrieve it. The selected part is added to the database.

Let him select the default role first:

Copy after login

To write his processing page:

strQuery($sql); break; }
Copy after login

Let’s take a look at the final result. If you log in successfully, you will enter the homepage. If you log in failed, you will get an error

## Come again, save button:

Copy after login

Processing page:

Query($sdel,0); //拆分取到的字符串 $arr= explode("|",$juese); foreach ($arr as $v) { $sql = "insert into qxyhzw VALUES ('','{$uid}','{$v}')"; $db->query($sql,0); } echo "ok"; break; }
Copy after login

See the effect:

The role is selected by default;

Choose to save after making changes:

#Management page summary Code:

无标题文档
          

用户与角色管理

请选择用户
请选择角色 Query($sjs); foreach ($ajs as $v) { echo " {$v[1]} "; } ?>
Copy after login

Total code for processing page:

strQuery($sql); break; case 1: $uid = $_POST["zhang"]; $juese = $_POST["juese"]; // 首先全部删掉里面的职位 $sdel = "delete from qxyhzw WHERE uid = '{$uid}'"; $db->Query($sdel,0); //拆分取到的字符串 $arr= explode("|",$juese); foreach ($arr as $v) { $sql = "insert into qxyhzw VALUES ('','{$uid}','{$v}')"; $db->query($sql,0); } echo "ok"; break; }
Copy after login

##3. Login page:

The display is very simple:

帐号:

密码:

Copy after login

Write login processing

strQuery($sql)>0; if($mm = $mi && !empty($mi)){ $_SESSION["zhang"] = $zhang; header("location:chaxun.php"); }//else //{ // echo "登入失败"; //}
Copy after login
Jump to the main page, main page code:

Everyone’s main page is different of

主页面

Copy after login
Query($sql);//根据角色代号查功能代号$attr = array();//定义一个存放功能代号的数组foreach ($aql as $v) { $jsid = $v[0];// 角色代号 $ssql = "select rid from qxgnzw WHERE jid='{$jsid}'"; $aaql = $db->strQuery($ssql);//拆分 $adai = explode("|",$aaql); foreach ($adai as $h) { array_push($attr,$h); } }$attr = array_unique($attr);//去重 //显示foreach ($attr as $k) { $ql = "select * from qxgn WHERE code = '{$k}'"; $arr = $db->Query($ql); arr[0][0]; $arr[0][1]; echo "

{$arr[0][1]}

"; }?>
Copy after login
Copy after login

用php的用户体验不好,最好还是得用ajax

The above is the detailed content of php personnel authority management (RBAC). For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!