Home >Backend Development >PHP Tutorial >An idea of ​​permission control_PHP tutorial

An idea of ​​permission control_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:14:501050browse

Database table structure

<span CREATE</span> <span TABLE</span><span  `NewTable` (
    `id`  </span><span int</span>(<span 11</span>) <span NOT</span> <span NULL</span><span  AUTO_INCREMENT,
    `title`  </span><span varchar</span>(<span 255</span>) <span NOT</span> <span NULL</span><span ,
    `menu_id`  </span><span int</span>(<span 11</span>) <span NOT</span> <span NULL</span><span ,
    `module`  </span><span varchar</span>(<span 50</span>) <span NOT</span> <span NULL</span><span ,
    `class`  </span><span varchar</span>(<span 50</span>) <span NOT</span> <span NULL</span><span ,
    `method`  </span><span varchar</span>(<span 50</span>) <span NOT</span> <span NULL</span><span PRIMARY</span> <span KEY</span><span  (`id`)
);</span>

Assume that we use the MVC structure and access the corresponding modules, classes and functions through url.

The first row in the table represents an operation, title represents the operation name, menu_id represents which menu option it belongs to, module represents the module name (can be omitted if not found), class represents the class name, and method represents the function name

In addition, we also need a user group table, roughly as follows:

The permission ID owned by the current user group saved in access_list (corresponding to the ID in the previous permission table)

Of course we also need a user table to correspond to the user group table

The user group corresponding to the user represented by group_id

When we visit a url, such as:

http://testApp.test.com/index.php/module/testModule/testClass/testAction

Through routing analysis, we get the corresponding data:

Module->testModule

Class->testClass

Function->testAction

Through three parameters, we look up the data in the permission table and get a unique id value.

Then compare the data in the access_list in the user group. If the data includes this id, then the current user has permission for the current operation, otherwise, he does not have permission.

So how do we control the menu options so that they are only displayed when the user has permission?

Because each operation in the permission table corresponds to a menu_id, which is the menu option. We find the user group information that the current user belongs to, get the permission operation ID he has, and then get the menu options he belongs to through the ID, thus getting the menu permissions owned by the current user.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440252.htmlTechArticleDatabase table structure ( ) ( ) ( ) ( ) ( ) ( ) ( ) Assume that we use the MVC structure, and Access the corresponding modules, classes and functions through url. The first row in the table represents an operation, and title represents the operation...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP Basics_PHP TutorialNext article:PHP Basics_PHP Tutorial