Set permissions in binary

前端 未结 5 1972
说谎
说谎 2020-12-29 16:06

I saw in school a system that set permissions using binary string.

Let\'s say 101001 = 41

So :

  • 1 can be permission to page 1
  • 2 can b
5条回答
  •  醉梦人生
    2020-12-29 16:40

    Here is a nice snippet. taken from here http://www.litfuel.net/tutorials/bitwise.htm

    ";
    if ($mike & 32) {
        echo 'YES MIKE CAN EDIT';
    } else {
        echo 'NO HE CANNOT';
    }
    
    echo "

    Is Jim Allowed to edit? he has an access level of 96
    "; if ($jim & 32) { echo 'YES JIM CAN EDIT'; } else { echo 'NO HE CANNOT'; } ?>

提交回复
热议问题