Skip to content

Instantly share code, notes, and snippets.

@dmitrybubyakin
Created December 8, 2016 09:50
Show Gist options
  • Save dmitrybubyakin/ec474cb052af4a9deebae660b8cb8cc4 to your computer and use it in GitHub Desktop.
Save dmitrybubyakin/ec474cb052af4a9deebae660b8cb8cc4 to your computer and use it in GitHub Desktop.
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