How to implement PHP Rights management function

Source: Internet
Author: User
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

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.