note 28964 deleted from language.operators.bitwise by sniper
| From: | sniper@php.net | Date: | Mon, 13 Oct 2003 00:13:01 +0000 |
| Subject: | note 28964 deleted from language.operators.bitwise by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58410@lists.php.net to get a copy of this message | ||
Note Submitter: kalle.alm@home.se
----
A way to create pretty efficient permission checks is:
define( "PERM_READ", 1 );
define( "PERM_WRITE", 2 );
define( "PERM_EDIT", 4 );
define( "PERM_DELETE", 8 ); /* etc as 16, 32, 64, 128, ... */
/* ... somewhere we set/get the user permissions and set them like ... */
$user_permissions = PERM_READ + PERM_WRITE + PERM_EDIT;
/* we grab the sum of the various permissions */
/* ... and then whenever we want to make sure a set of permission prerequisites are met by the
user's permission we call: */
function request_privs( $got_perm, $need_perm ){
if( ($got_perm & $need_perm) == $need_perm ) return;
echo( "Permission denied!" );
exit;
}