10-12-2008, 03:53 PM
|
#136 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Sorry for going slightly off topic, but to answer Jim's question:
Quote:
Originally Posted by Jim
Bits? What be that?
|
Using bits for user permissions, like this example:
PHP Code:
class level_flags { const VIEW = 0x01; const ADD = 0x02; const DELETE = 0x04; const EDIT = 0x08; } // Set the user's permissions $userFlags = level_flags::ADD | level_flags::EDIT;
// Does the user have permission to VIEW? if($userFlags & level_flags::VIEW) { die('Yes'); } else { die('Go away!'); }
Here i have used hex to show each permission and used the & bitwise operator to check if the correct bits are set, thus giving us a powerful permission system.
This particular example returns 'Go Away!' because the VIEW isnt set within $userFlags which only has ADD and EDIT bits set.
This technique is used in a script that Wildhoney posted not long ago: Easy to Modify Login Script with Hierarchical User Permissions and XML Account File
Here is a great bitwise resource: PHP Bitwise Tutorial by Jim Plush
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|