Lots of ways to skin this cat depending on your architecture and preferences: are you using db abstraction? are you using classes? etc?
My prefered method, whatever the platform and paradigm, is simple boolean switches.
In vb I use 'rules' in the GUI:
if CanChange() then
...
end if
CanChange() is a simple get that returns True/False from a global class of user privileges.
In php I would suggest the following
Create a series of BIT columns in the 'user_roles' table, each one named for an access privilege and set to True/False per role. When your stored proc returns the user role it should return the BIT columns as well.
Then just push them into the session array, eg your login function returns a row with user name, password, role and all bit columns, or false if login authentication failed.
if (!$login) {
// boot them off to somewhere
} else {
foreach ($login as $key=>$val) {
$_SESSION[$key] = $val;
}
}
// then when you build your menu
if ($_SESSION['add_user']) {
echo '<li><a href="adduser.php">Add User</a></li>';
}
// if they don't have the add user privilege then it just won't be on the menu to start with
// you could also check it at the top of the adduser.php page
if (!$_SESSION['add_user']) {
echo 'YOU ARE NOT ALLOWED TO DO THAT';
exit;
}
Once a user has logged in then all the privileges are set automatically no matter the role. Because it is using the session array it can be done anywhere whether in a class or function or whatever.
The beauty of this is the flexibility, role privilege changes then just change the value in one column; add role then at the same time set the flags; new functionality then just add a column to the table and set the flags for each role.
You can get really funky with this if you use the exact same names for the column, privilege, script etc cos php lets you use variable var names - but I would not trust it myself.