note 73088 added to language.operators.bitwise
| From: | bryanagee at gmail dot com | Date: | Thu, 08 Feb 2007 19:19:58 +0000 |
| Subject: | note 73088 added to language.operators.bitwise | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123128@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 71.34.217.179
----
Manual Page -- http://www.php.net/manual/en/language.operators.bitwise.php
Edit -- https://master.php.net/note/edit/73088
Del: integrated -- https://master.php.net/note/delete/73088/integrated
Del: useless -- https://master.php.net/note/delete/73088/useless
Del: bad code -- https://master.php.net/note/delete/73088/bad+code
Del: spam -- https://master.php.net/note/delete/73088/spam
Del: non-english -- https://master.php.net/note/delete/73088/non-english
Del: in docs -- https://master.php.net/note/delete/73088/in+docs
Del: other reasons-- https://master.php.net/note/delete/73088
Reject -- https://master.php.net/note/reject/73088
Search -- https://master.php.net/manage/user-notes.php