im trying to learn to use bitwise permissions for in my application. Problem is, it's not working :(
When a user logs in, i save a user object in the session, which looks like this :
[user] => User Object ( [id] => 1 [firstname] => Firstname [lastname] => Lastname [emailaddress] => email@adres [permissions] => 16 ) i have a class called authenticate, in which i define some contants, which are these :
class authenticate { const GUEST = 1; // 1 const USER = 10; // 2 const MODERATOR = 1000; // 8 const ADMIN = 10000; // 16 Now when a user logs in in the admin, i want to make sure the user has admin rights, which i try to check this way :
if ($_SESSION['user']->permissions & authenticate::ADMIN){ echo 'yep admin'; }else { echo 'no admin'; } When i have a user that does lets say have a number 8 as permission, its not an admin and it should say no admin.. but it doesn't it always says yep admin ..
could anyone tell me what i am doing wrong here?
Thanks!
perm & required_perm === required_perm. (Though maybe not.) PHP 5.4+ supports binary literal notation in the form0b0101.$_SESSION.