PHP permission design solution

Source: Internet
Author: User
PHP permission design description: I want to create a PHP permission menu, and cyclically export different main menus and sub-menus from the database based on different user logon. the database structure is as follows: pai_useraccount \ stores user information pai_role \ stores role information pai_resource \ store menu information pai_pe about PHP permission design
Description: I want to create a PHP permission menu. different main menus and submenus are cyclically generated from the database based on different user logins.
The database structure is as follows:
Performance_useraccount \ stores user information
Performance_role \ stores role information
Performance_resource \ stores menu information
Permission of role _permission \

Now, you can obtain the user ID obtained at login, the main menu owned by the user, but what should you do if you get the sub menu owned by the user? No clue
\ Select. roleID, B. resourceName, B. URL from pai_permission a join pai_resource B on. resourceID = B. resourceID where RoleID in (select RoleID from resource_useraccount where username = 'admin ');



PHP code
  // Database CIMcreate database cim default charset = utf8; // create table into _useraccount (ID int (4) not null primary key AUTO_INCREMENT, UserName varchar (20 ), passWord varchar (20), MobilePhone varchar (20), CreateTM varchar (20), UpdateTM varchar (20), RoleID int (4) default charset = UTF8; // data format and insert test data insert into useraccount (UserName, PassWord, MobilePhone, CreateTM, RoleID) values ('admin', '123', '123' 8564 ', '1970-12-30', '10'); insert into your _useraccount (UserName, PassWord, MobilePhone, CreateTM, RoleID) values ('Liu Cheng', '123 ', '123', '1970-12-30 ', '20'); insert into your _useraccount (UserName, PassWord, MobilePhone, CreateTM, RoleID) values ('{qiongfang', '123 ', '123', '1970-12-30 ', '30'); // create table role _role (RoleID int (4), RoleName varchar (20 ), remark varchar (20) default charset = UTF8; // Insert test data I Nsert into role _role (RoleID, RoleName, Remark) values ('10', 'super admin', 'all system authorization'); insert into role _role (RoleID, RoleName, Remark) values ('20', 'technical department ', 'with permissions for customer service management'); insert into role _role (RoleID, RoleName, Remark) values ('30', 'Department manager ', 'permission to modify information'); insert into role _role (RoleID, RoleName, Remark) values ('40', 'Finance manager', 'attendance statistics and bonuses '); // resource table create table resource_resource (ResourceID int (4), ResourceName varchar (20), Remark varchar (20), U RL varchar (100),); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20140901', 'customer service management', 'managing routine customer service records ', 'sevicemanager. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('000000', 'customer service submenu 1', 'managing routine customer service records ', 'sevicemanager. php? Action = add'); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20170101', 'customer service submenu 2', 'managing routine customer service records ', 'sevicemanager. php? Action = del '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20140901', 'Member management', 'Member addition and query', 'memberservice. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20170101', 'query management', 'query management', 'search. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('000000', 'Return Visit management', 'Return Visit to customer service record', 'Visit. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20140901', 'knowledge base', 'product FAQ ', 'knowledge. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20170101', 'data management', 'data Backup statistics relevance', 'backup. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20170101', 'hardware failed', 'hardware failed', 'repair. php '); insert into resource_resource (ResourceID, ResourceName, Remark, URL) values ('20140901', 'system management', 'system management', 'system. php '); create table rule _permission (RoleID int (4), ResourceID int (4) // permission table insert into rule _permission (RoleID, ResourceID) values ('10 ', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10 ', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10 ', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10 ', '20140901'); insert into attributes _permission (RoleID, ResourceID) values ('10', '123 ');



------ Solution --------------------
Some suggestions

1. it seems that tables can be merged into one
2. for permissions, you can assign the value to the session after the read permission.
Then, according to the permission include menu/sub menu content

Of course, if is used for permission judgment. This should be done by php, rather than "read" by mysql.

Write the permission judgment into a class, and then include different files.
------ Solution --------------------
Related Article

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.