Jump to content

Recommended Posts

Hello Everyone,

I am a beginner at PHP... I have created a simple CMS which have a LOGIN and USER TABLE in DATABASE.. Now I want to create menus and create four catagories for user as Super Admin, Admin & publisher and want to give them rights for menu access...

Please help

Link to comment
https://forums.phpfreaks.com/topic/266334-cms-menu-rights-for-users/
Share on other sites

the way i do it is add a field to database table called access_level

 

in my case I need to control 2 things .. page view and page content items (menu links in your case).

 

I wrote 2 functions ..

1. can_i_be_here($allowed_levels)

this function checks the allowed levels to see if the users access_level is allow to view. if not it redirects to the previous page.

 

2. can_i_see_this($allowed_levels)

this function checks to see if the users access_level is allowed to see the item in question. it just returns true or false.

 

i use them like this

if(can_i_be_here('5|9'))
{
run code and display content.

}

 

 

and

 

if(can_i_see_this('2|9'))
{
    echo 'this is my content only you can see';
}

 

this is a very basic explanation, but it should get you pointed in the right direction.

 

hope it helps.

I got you! But can't i do it in this process?

-> Create 'menus' table in database which has 'id, menu_name, link' as fields.

-> Then, create 'menu_rights' table in database which has 'menu_id, user_id' as fields.

-> Then, create relationships between these two tables.

 

But i can't do so.... :(

You should just be assigning roles and permissions in the database, and then use PHP to figure out which menus they can access based on the aforementioned roles and permissions.

 

Check out this article: http://phpmaster.com/role-based-access-control-in-php/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.