The idea of "authority management" is best achieved by "role" + "privilege".

Source: Internet
Author: User
Permissions role

Title...

In front of complex permission settings, direct handwriting If, else I think it's not going to work.

Ideas for advice


Reply to discussion (solution)

You should have a permission table when you are building a table, a property of the role the foreign Key associates the table

You should have a permission table when you are building a table, a property of the role the foreign Key associates the table

Can you say something more detailed? The main point is to write the program in which link should be introduced in this permission to determine how to introduce

Previously wrote a small project is also a permission problem, we solve this: when the user login to the user's information (including permissions, I was at that time the permission is a number.) If the user right is 5) exists in the session, when he wants to do an operation such as delete (permission requirements to >6), compare the current permissions and the size of the required permissions .... It's too far to remember.

General identity (login) to introduce a role to the session, and then according to the role of the table to get permissions

Table Design: Role context menu (Level menu ~ Level Two menu ...) ), Role Association actions (view, delete, search, modify)

Determine the representation and storage of permission words first
The integer number of PHP is Logn type, with 64 bits.
Therefore, it is sufficient to meet the needs of most applications. (Each bits represents an action)

Each role has a permission word, and each user can have multiple roles
Each user can also have an exception permission word

The comprehensive permission uses the bitwise operation to find out:
User Rights = Role Permissions XOR exception
Where: Role permissions = User Membership role permissions or user Membership role permissions ...

Roles <-> permissions; permissions <-> menus

Determine the representation and storage of permission words first
The integer number of PHP is Logn type, with 64 bits.
Therefore, it is sufficient to meet the needs of most applications. (Each bits represents an action)

Each role has a permission word, and each user can have multiple roles
Each user can also have an exception permission word

The comprehensive permission uses the bitwise operation to find out:
User Rights = Role Permissions XOR exception
Where: Role permissions = User Membership role permissions or user Membership role permissions ...

Thank. The storage and allocation of permissions is very clear.

How do you use it specifically when you call?

Like now there's a delete button

Roles with delete permission can see this button when they view this page, how to write? With If, else?

Click the Delete button to submit to PHP also need to determine the permissions?

Condition judgment is always necessary, otherwise how to know who is who?
But it's simple.
$u = 0b1011; User Rights
$p = 0b0010; Action number (I've already told you there are 64 kinds of actions)
if ($p & $u) echo ' has permission ';

Look for RBAC Design patterns

User table associated User Group table, User Group Table association permissions table, when the user entered, first determine which group, and then set permissions according to the group, many open source products are so designed.

Simple roles Store Each method, using this method to determine if the user role has this method permission

RBAC permission mode It can be a lot of these online, you can check

  • 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.