Jump to content

[SOLVED] Role based access control in php


chaiwei

Recommended Posts

Hi all,

 

anyone know what is the effective way to implement the role based access control in php?

the RBAC is like there got Root,Admin,manager,normal user,guest.

 

1)Root can only have 1, have all the access in the system,

2)Admin can create manager and user,have access to update delete insert, but not allow to create      root nor another admin.

3)Manager can create bla bla bla.

 

like setting permission. Actually i have found that there is a way to of using bitmask.

 

define(addAdmin,1);
define(addManager,2);
defime(addUser,4);
define(update,;
define(edit,16);
define(delete,32);

$manager=4+8+16+32;
$manager=60;

$arr = bitMask($manager);   //return array(0=>4, 1=>8, 2=>16, 3=>32 );

if(in_array(edit,$arr){
  echo 'Login Successful';
}else{
  echo 'Invalid Login';
}

 

I am not sure whether this is the effective way to set user roles,

if I am stored this value (60) in the session or cookie, I am consider for the security issue.

let say setcookie('PERMISSION',60);

 

what if manager manually rewrite the setcookie('PERMISSION',63)

then it can addAdmin and addmanager also.

 

Is there any effective way to do set the roles access control?

any 1 know how drupal done that?

I mean the concept or idea to set the roles.

 

 

[pre][/pre]

function bitMask($mask = 0) {
    if(!is_numeric($mask)) {
        return array();
    }
    $return = array();
    while ($mask > 0) {
        for($i = 0, $n = 0; $i <= $mask; $i = 1 * pow(2, $n), $n++) {
            $end = $i;
        }
        $return[] = $end;
        $mask = $mask - $end;
    }
    sort($return);
    return $return;
}

[pre][/pre]

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.