manishrestha529 Posted July 27, 2012 Share Posted July 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266334-cms-menu-rights-for-users/ Share on other sites More sharing options...
severndigital Posted July 27, 2012 Share Posted July 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266334-cms-menu-rights-for-users/#findComment-1364841 Share on other sites More sharing options...
manishrestha529 Posted July 27, 2012 Author Share Posted July 27, 2012 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.... Quote Link to comment https://forums.phpfreaks.com/topic/266334-cms-menu-rights-for-users/#findComment-1364846 Share on other sites More sharing options...
scootstah Posted July 27, 2012 Share Posted July 27, 2012 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/ Quote Link to comment https://forums.phpfreaks.com/topic/266334-cms-menu-rights-for-users/#findComment-1364852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.