Measure the test taker's knowledge about the implementation of RBAC for php personnel.

Source: Internet
Author: User
Before permission management, you should first know what functions should be provided for permission management: (1) users can only access the specified controller, and the specified method (2) users can exist in multiple user groups (3). user groups can be selected. the specified controller refers Before talking about # code/12171.html "target =" _ blank "> permission management, you should first know what features should be provided for permission management:

(1) users can only access the specified controller and method.

(2) users can exist in multiple user groups.

(3) users can select the specified controller and method.

(4) you can add controllers and methods.

Role-Based Access Control (RBAC) is used to associate users with permissions through roles. Simply put, a user has several roles and each role has several permissions. In this way, the authorization model of "user-role-permission" is constructed. In this model, the relationship between users and roles and between roles and permissions is usually many-to-many.

2. administrator management page,

(1). display the user name and role name respectively.

(2). change the role in the check box according to the change in the drop-down user name.

(3) When modifying a user role, you must first delete all user information in the table corresponding to the user role, and then add the obtained user name and role code.

Use the drop-down list: embedded php query and Traverse. the following drop-down list is displayed:

  
  Query($sql);      foreach ($arr as $v)    {            echo "{$v[2]}";    }        ?>

Select a role. use the multiple choice box:

Select a role Query ($ sjs); foreach ($ ajs as $ v) {echo"{$ V [1]} ";}?>

Figure:

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

First, let him select the default role:

Script // select the default role function xuan () {var uid = $ ("# user "). val (); $. ajax ({url: "chuli. php ", data: {uid: uid, type: 0}, type:" POST ", dataType:" TEXT ", success: function (data) {var juese = data. trim (). split ("|"); // The Code var ck = $ (". ck "); ck. prop ("checked", false); for (var I = 0; I
 
  
= 0) {ck. eq (I). prop ("checked", true) ;}}});} script
 

To write his processing page:

 strQuery($sql);break;}

Check the final result. after successful logon, the homepage is displayed. if logon fails, an error is returned.

Then, click the save button:

Script // select the corresponding role $ ("# user") when the user changes "). change (function () {xuan () ;}) // Click OK to save the role information $ ("# btn "). click (function () {var uid = $ ("# user "). val (); // find the username var juese = ""; // find the role code var ck = $ (". ck "); // find all checked for (var I = 0; I
 
  

Processing page:

   Query ($ sdel, 0); // string obtained by splitting $ arr = explode ("|", $ juese); foreach ($ arr as $ v) {$ SQL = "insert into qxyhzw VALUES ('', '{$ uid}', '{$ v}') "; $ db-> query ($ SQL, 0);} echo "OK"; break ;}

View results:

Total management page code:

    Untitled Document    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.