Dear all,

I have a challenge here of understanding the page masks as used in this code;

<?
    $access_level_map['loader']     = 1;
    $access_level_map['support']    = 3;
    $access_level_map['admin']      = 7;
    $access_level_map['superadmin'] = 15;

    define("LOAD_PAGE_MASK",1);
    define("SUPPORT_PAGE_MASK",2);
    define("ADMIN_PAGE_MASK",4);
    define("SUPER_ADMIN_PAGE_MASK",8);

    $pageMaskMap['add_employee.php'] = SUPPORT_PAGE_MASK;

    $pageMaskMap['awpdc.php'] = SUPPORT_PAGE_MASK;
    $pageMaskMap['awpdc_blocked.php'] = SUPPORT_PAGE_MASK;
    $pageMaskMap['awpdc_unblocked.php'] = SUPPORT_PAGE_MASK;

?>

What I know is that this page controls which user can access what page. However, I have been tasked to add another user to this mask, and I have no idea on how to go about this one.
Any help will be greatly appreciated.

Thanx

Member Avatar for diafol

support and above users can view those.

You can check if the current user has permission to view the pages with a bitwise operator:

if($myAccessLevel & $thisPageMask)
{
    //Allow entry
}else{
    //header away
}

For example if my accesslevel was support (3) and the pagemask was load (1), then because 3 and 1 have a common "1 bit": 11 and 01 - they match.

Other examples:

loader 1 (1)
support 11 (3)
admin 111 (7)
superadmin 1111 (15)

loaderMask 1 (1)
supportMask 10 (2)
adminMask 100 (4)
superadminMask 1000 (8)

So when you compare and get matched bits, you allow access to the page. E.g.

superadmin 1111 and superadminMask 1000 but not

admin 111 and superadminMask 1000

Aaaah, I get it now; So that means that if I add another user, say a Manager, then I'd do something like;

$access_level_map['loader'] = 1;
$access_level_map['support'] = 3;
$access_level_map['admin'] = 7;
$access_level_map['superadmin'] = 15;
$access_level_map['manager'] = 31;

define("LOAD_PAGE_MASK",1);
define("SUPPORT_PAGE_MASK",2);
define("ADMIN_PAGE_MASK",4);
define("SUPER_ADMIN_PAGE_MASK",8);
define("MANAGER_PAGE_MASK",16);

Is that correct???

Member Avatar for diafol

Yep!

Awesome, Thanx a bunch.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.