PHP implements permission management, and php implements permission management.

Source: Internet
Author: User

PHP implements permission management, and php implements permission management.

The permission management system is mainly used to set different permissions for different users, so that users with different permissions can use different functions after logon.

First, let's take a look at the database.

A total of five tables, users, roles, and roleswork, form a "w" relationship with the other two tables. This is also a common method of permission database, first, Set permissions first, that is, the management layer sets different permissions for different users.

1. Administrator page RBAC. php

<! DOCTYPE html> // When the user selects and changes, select the corresponding role sel ();})
// Click OK to save the role information $ ("# btn "). click (function () {var uid = $ ("# user "). val (); var ck = $ (". ck "); var role =" "; // It is null for (I = 0; I <ck. length; I ++) {var v = ck. eq (I ). val (); if (ck. eq (I ). prop ("checked") {role + = ck. eq (I ). val () + "|" ;}}$. ajax ({type: "POST", url: "RBbtnchuli. php ", data: {uid: uid, role: role}, dataType:" TEXT ", success: function (data) {alert (" modified successfully! ");}});})
// Function sel () {var uid = $ ("# user "). val (); $. ajax ({url: "RBchuli. php ", data: {uid: uid}, type:" POST ", dataType:" TEXT ", success: function (data) {var role = data. split ("|"); var ck = $ (". ck "); ck. prop ("checked", false); for (I = 0; I <ck. length; I ++) {var v = ck. eq (I ). val (); if (role. indexOf (v)> = 0) {ck. eq (I ). prop ("checked", true) ;}}}) ;}</script>

2. Make the Administrator's processing page RBchuli. php

<?php$uid = $_POST["uid"];require_once "./DBDA.class.php";$db = new DBDA();$sql = "select rolesuid from users_roles where usersuid='{$uid}'";echo $db->StrQuery($sql,0);

Save role information processing page RBbtnchuli. php

<? Php $ uid = $ _ POST ["uid"]; $ role = $ _ POST ["role"]; // string $ role = substr ($ role, 0, strlen ($ role)-1); $ arr = explode ("|", $ role); require_once ". /DBDA. class. php "; $ db = new DBDA (); // delete $ sdel =" delete from users_roles where usersuid = '{$ uid }'"; $ db-> query ($ sdel); // Add foreach ($ arr as $ v) {$ SQL = "insert into users_roles values (0, '{$ uid }', '{$ v}') "; $ db-> query ($ SQL );}

Effect

 

 

 

Next, log on to an account and view its functions.

3. User Logon page RBlogin. php

<! DOCTYPE html> 

4. RBloginchuli. php

<? Phpsession_start (); $ uid = $ _ POST ["uid"]; $ pwd = $ _ POST ["pwd"]; require_once ". /DBDA. class. php "; $ db = new DBDA (); $ SQL =" select pwd from users where uid = '{$ uid }'"; $ mm = $ db-> StrQuery ($ SQL, 0); if (! Empty ($ pwd) & $ pwd ==$ mm) {$ _ SESSION ["uid"] = $ uid; header ("location: RBmain. php ");} else {echo" <script> alert ('the user name or password is incorrect! ') </Script> ";}

5. Finally, the user's home page RBmain. php

<! DOCTYPE html> 

Effect

 

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.