Created
December 8, 2016 09:50
-
-
Save dmitrybubyakin/ec474cb052af4a9deebae660b8cb8cc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
roles | |
role | description | |
------------------------- | |
15 | admin | |
5 | user | |
9 | guest | |
rights | |
right | description | |
------------------------- | |
2 | can add posts | |
4 | can del posts | |
8 | can comment | |
16 | can edit | |
32 | can fly | |
64 | can eat | |
15 = 1|2|4|8 | |
15 & (2 or 4 or 8) !== 0 ==> has access | |
15 & (16 or 32 or 64 or ...) === 0 ==> hasn't access | |
5 = 1|4 | |
5 & (4) !== 0 | |
5 & (2,8,16,32, ...) === 0 | |
9 = 1|8 | |
function check($role,$right){ | |
return !!($role & $right); | |
} | |
check(15,2) => true | |
check(15,16) => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment