hey everybody ;

i want to hide some tabs in the menu for users according to their privileges ;
my table : user (id, name , pwd , state , histotic , report)
state , historic and report ill take values : yes or no . and according to that
if user 1 will have : state = yes , historic=no , report = no it means that in the menu the too tabs : historic and reort will be hidden .
is it possible to do it in php ?? if it is any ideas how can i start it ??
thank u so much for helpin me

Recommended Answers

All 5 Replies

yes it is possible to do.
I am hoping that menu is coming from Database,if not then its good to create dynamic menu from DB if you want it to more customizable.
table structure can be
memu(id int not null AUTO_INCREMENT,display varchar(20) not null,isMenuItem tinyint(1))
Now query to get value of state , historic and report (make them also tinyint(1) instead of boolean).and query to check all value from menuitem where isMenuItem = 1 and for each of them chck there values.

Member Avatar for diafol

You can do this with a DB or you could have the data as an array in a config file. Doesn't really matter I suppose. Depending on how complicated your menu system is - how nested etc. A well designed array can often be easier to maintain funnily enough. Unless you design an interface to the DB table, you could find yourself going around in circles, trying to remember which id belongs to which child or parent. :)

Having said that, most cms use DBs, as they have robust DB interface forms.

Yes it is very possible. Personally, I use it quite often.
What I do is, when I am registering user accounts, I specify the user type, which can be represented by numbers. For instance, Administrator has user type 1, Clerk; user type 2 and so forth.
When it comes to my form, I create two different menus for each user. For example clerk_menu.php for the clerk and admin_menu.php for the admin. I prefer this, because at times fetching everything from the database can take a while.
Then, I just include the necessary menu page to the corresponding page. For instance, on a page that is accessed by the admin, then I include the menu, like so;


And the same is done for the clerk.

Hope that guides you on how to go about it.

Member Avatar for diafol

As an extra- remember to protect each page that falls under 'admin'. You can do this with a simple header() that redirects users without sufficient rights.

Yeah, just as diafol put it. You have to track users, this is doen using sessions. Therefore, you can put something like this at the top of each page;


if($_SESSION['username'] == "" && $_SESSION['password'] =="") // First check if a user is logged in
header ('Location: index.php');
if($_SESSION['user_type'] == 1)
else if($_SESSION['user_type'] == 2)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.