I am working on a user-role / permission system in PHP for a script.
Below is a code using a bitmask method for permissions that I found on phpbuilder.com.
B
The first allows people to have lots of permissions - read/add/update for example. The second example, the user has just PERMISSION_UPDATE
.
Bitwise testing works by testing bits for truth values.
For example, the binary sequence 10010
would identify a user with PERMISSION_DELETE
and PERMISSION_READ
(the bit identifying PERMISSION_READ
is the column for 2, the bit identifying PERMISSION_DELETE
is the column for 16), 10010
in binary is 18 in decimal (16 + 2 = 18). Your second code sample doesn't allow you to do that sort of testing. You could do greater-than style checks, but that assumes everyone with PERMISSION_DELETE
should also have PERMISSION_UPDATE
, which may not be a valid assumption.