I'm currently learning how vBulletin works and I've hit a hurdle on the permissions system they have in place.
They have an array like such:
Code: Select all
<?php
// field names for administrative permissions
$_BITFIELD['usergroup']['adminpermissions'] = array(
'ismoderator' => 1,
'cancontrolpanel' => 2,
'canadminsettings' => 4,
'canadminstyles' => 8,
'canadminlanguages' => 16,
'canadminforums' => 32,
'canadminthreads' => 64,
'canadmincalendars' => 128,
'canadminusers' => 256,
'canadminpermissions' => 512,
'canadminfaq' => 1024,
'canadminimages' => 2048,
'canadminbbcodes' => 4096,
'canadmincron' => 8192,
'canadminmaintain' => 16384,
'canadminupgrade' => 32768
);
?>Code: Select all
<?php
// final bitfield check on each permission we are checking
foreach($do AS $field)
{
if ($adminperms & $_BITFIELD['usergroup']['adminpermissions']["$field"])
{
return true;
}
}
?>I understand the basics of the mathematics but I don't understand exactly how it works. For example, if I wanted to add a new permission I guess I would just add the next base2 value to the array for the permissions but I don't understand how and why it works