/ Published in: PHP
Usage:
define('PIRATE',bindec('0001')); // 1
define('NINJA',bindec('0010')); // 2
define('JEDI',bindec('0100')); // 4
define('ADMIN',bindec('1000')); // 8
$rpermit = array(PIRATE,JEDI); // Equivilent Flags '0101'
$jim['permission'] = ADMIN + JEDI; // 12
$joe['permission'] = ADMIN + NINJA; // 10
$jon['permission'] = PIRATE; // 1
var_dump(isPermitted($rpermit,$jim['permission']));
var_dump(isPermitted($rpermit,$joe['permission']));
define('PIRATE',bindec('0001')); // 1
define('NINJA',bindec('0010')); // 2
define('JEDI',bindec('0100')); // 4
define('ADMIN',bindec('1000')); // 8
$rpermit = array(PIRATE,JEDI); // Equivilent Flags '0101'
$jim['permission'] = ADMIN + JEDI; // 12
$joe['permission'] = ADMIN + NINJA; // 10
$jon['permission'] = PIRATE; // 1
var_dump(isPermitted($rpermit,$jim['permission']));
var_dump(isPermitted($rpermit,$joe['permission']));
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php return ($resourcePermission & (int)$userPermission)?true:false; } ?>
URL: http://www.litfuel.net/tutorials/bitwise.htm