I want to deploy rbac solution in my app. I found solution to use bitwise operators and it’s work but I have two problems.
- In global meaning permission “write” is upper than “read” and obviously permission “write” sholud contain permission “read”?
- For example I have page where I have form and inputs and I want to user access only read so I sholud use conditional “if else” ? If yes, that I have to two reapet the same code. One of conditional has to block form and inputs?
$read = 1;
$write = 2;
$deleteUsers = 4;
$user = $read;
$employee = $read | $write;
$admin = $read | $write | $deleteUsers;
function checkPermission($person, $permission)
{
if($person & $permission) {
return true;
}
}
if(checkPermission($admin, $deleteUsers))
{
echo "Access granted";
}