note 28964 added to language.operators.bitwise

From: Date: Wed, 29 Jan 2003 11:06:56 +0000
Subject: note 28964 added to language.operators.bitwise
Groups: php.notes 
Request: Send a blank email to php-notes+get-43039@lists.php.net to get a copy of this message
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; } -- http://www.php.net/manual/en/language.operators.bitwise.php http://master.php.net/manage/user-notes.php?action=edit+28964 http://master.php.net/manage/user-notes.php?action=delete+28964 http://master.php.net/manage/user-notes.php?action=reject+28964

« previous php.notes (#43039) next »