Page 2 of 2

Posted: Thu Dec 14, 2006 10:27 pm
by Burrito
Everah wrote:What happens when you want to add a permission in between 4 and 8?
the permissions themselves wouldn't have a value between 4 and 8. A user level might though. Let's assume a user has a level of 5.

in binary that's:

Code: Select all

0101
that user would match a permission privilege of 4 and 1, but not 2 and 8.

the cool thing is you can save a user's permission level as an integer on the db (or in a session var) and compare it against the binary permissions using the & operator as Begby outlined above.

so for permission privilege '4':

a user with permission level 5 would match
a user with permission level 6 would match
a user with permission level 7 would match
a user with permission level 8 would not match
etc...