Before we talk about rights management, we should know the functions of rights management:

(1) The user can only access the specified controller and specified method

(2) Users can exist in multiple user groups

(3) The user group can select the specified controller and specified method

(4) You can add controllers and methods

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

1. Database design

Write five tables, first: user table, role table, function table:


Join table table.. Next comes the role list and user role list:

2. Administrator management page,

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

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

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

Make use of drop-down lists: Embed the PHP query and iterate over it, displaying it as a drop-down list

To select a character, use the following boxes:

Graph:

When the user changes, the corresponding role also changes accordingly, and changes the role information of the personnel, add and save, add and save the basic idea is to delete all the corresponding role information of the personnel in the database, and then take the selected part and add it to the database.

First let him select the default role:

To write his processing page:

Let’s take a look at the final result, login success will enter the home page, login failure will prompt an error

Again, save button:

Processing page:




See the effect:


The role is selected by default.

Select Save after change: