The following small series to bring you a PHP implementation of the Rights management function example. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
Rights management system, it is mainly in order to give different users to set different permissions, so that users with different permissions to log on after the use of the same function.
First look at the database
There are a total of 5 tables, users,roles and roleswork 3 tables with another 2 tables form a "W" type of relationship, is also a more common way to access the database, first of all to do the permission set, that is, the management layer to different users set different permissions.
1. Admin page rbac.php
<! DOCTYPE html>
2. Do the admin processing page rbchuli.php
<?php$uid = $_post["UID"];require_once "./dbda.class.php"; $db = new Dbda (); $sql = "Select Rolesuid from Users_roles whe Re usersuid= ' {$uid} ', Echo $db->strquery ($sql, 0); Save the processing page for role information rbbtnchuli.php
Save the processing page for role information 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
The next thing to do is log in to an account and see your own functions.
3. User Login Page rblogin.php
<! DOCTYPE html>4. The processing page of the login page 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 (' username or password is incorrect! ') </script> ";}
5. Finally do the user's homepage face rbmain.php
<! DOCTYPE html>
Effect