note 73088 deleted from language.operators.bitwise by cmb
| From: | cmb@php.net | Date: | Sun, 20 Oct 2019 08:49:31 +0000 |
| Subject: | note 73088 deleted from language.operators.bitwise by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212696@lists.php.net to get a copy of this message | ||
Note Submitter: bryanagee at gmail dot com
----
I found the 31-bit limitation on the bitwise ands to be a bit frustrating in large scale permission
control applications. I have a situation involving page-level access with more than 50 pages. I was
able to workaround the limitation by adding a loop that dropped 31 bits off of the right until the
resource identifier bit is within the first 31.
<?php
$userlevel = $session->userlevel - 0; # the subtraction ensures int type
$pg_code = pow(2,($pg_id-1));
while ($pg_code >= 2147483648) {
$pg_code = $pg_code/pow(2,31);
$userlevel = $session->userlevel/pow(2,31) ;
}
if (!($userlevel - 0 & $pg_code)) {
#if not authorized, show the unauthorized page
header('Location: Unauthorized.php');
exit;
}
?>