Re: Suggestions please!
| From: | Joseph Crawford | Date: | Tue, 22 Nov 2005 15:57:01 +0000 |
| Subject: | Re: Suggestions please! | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-40715@lists.php.net to get a copy of this message | ||
you might want to create a table called perms and have each row contain a
user id and a perm for each
the way i have mine setup is a bit more complex but fully configurable.
Here's how i would set it up
user_permissions
- user_id
- action
- value
user_actions
- id
- title
users
- id
- username
- passwd
then to get the permissions i would use a user object maybe something like
this
class user {
var $_id;
var $_permissions;
function user() {
$this->loadPermissions();
}
function hasPermission($val) {
$perm = $this->getPermission($val);
if(isset($perm) && $perm == 1) return true;
else return false
}
function loadPermissions() {
global $db;
$res = $db->Query("SELECT user_permissions.value, user_actions.title value
FROM user_permissions INNER JOIN user_actions ON
user_permissions.action==user_actions.id"
$data = $db->fetchAll($res);
return $data
}
}
Understand that this code will not work out of the box and no security
measures were implemented, i did this just to show an example ;)
In my system i have user permissions and group permissions, i load the group
permissions then override with the user permissions.
--
Joseph Crawford Jr.
Zend Certified Engineer
Codebowl Solutions, Inc.
1-802-671-2021
codebowl@gmail.com