I'd like to create a website with different user permissions. Not all users can do the same and they shouldn't even be able to view the same. Is the best solution to handle this with different pages? So if a user with highter permission logs in, he will be redirected to a page with other/more functions?
Asked
Active
Viewed 886 times
1
-
Set roles for user types – Mar 05 '20 at 08:13
-
One way of doing it would be to create a table for user groups, each user in a specific group. Based on in which group the current user is you can then show different things. For example an admin group (id 1) and a user group (id 2), and a column for the group id inside your user table. – matkv Mar 05 '20 at 08:17
-
take a look at this https://stackoverflow.com/questions/4415663/implementing-acl-for-my-php-application , I think it can help you – ArashShiri Mar 05 '20 at 08:41
-
@matkv and then just hide the content? – fnm65404 Mar 05 '20 at 09:02
-
@fnm65404 you can then `include(link)` certain files based on which user they are. – matkv Mar 05 '20 at 09:14
1 Answers
1
For this, you will have to use role and permission management in your DB level.
Create a table with the name of the role
Role Table(role)
id role_name
1 Super-Admin
2 Admin
3 User
Users Table(users)
id name role_id
1 James 1
2 Jack 2
Permission Table(permission)
id page_name
1 View Users List
2 Dashboard
3 Update User
Role Permission Table(role_permission)
role_id permission_id
1 1
1 2
2 2
When the user logged in successfully then get the user role_id by the user's table and list all the permission for that role id and then redirect according to your needs.
select rp.role_id,p.page_name from role_permission as rp inner join permission p
on p.id = rp.permission_id where rp.role_id = 1(role id of the user)
Hope this will help you.

Shubham Azad
- 786
- 2
- 10
- 25
-
Thanks for your answer :). So there are three different pages at the end? – fnm65404 Mar 05 '20 at 09:06
-
No, It is an example of three pages. You can create pages according to your need. – Shubham Azad Mar 05 '20 at 09:10
-
core PHP, I though that when a user logs in, it checks his permissions and redirects him to the corresponding page. Is this wrong? – fnm65404 Mar 05 '20 at 09:17
-
-
So if I am for examople user Jack (admin) I have access to dashboard, haven't I? – fnm65404 Mar 05 '20 at 09:43
-
yes you can access the dashbaord page. run this query select rp.role_id,p.page_name from role_permission as rp inner join permission p on p.id = rp.permission_id where rp.role_id = 2 – Shubham Azad Mar 05 '20 at 09:49