Jump to content

Array Help


Skepsis

Recommended Posts

Okay, so let me explain what i'm trying to do.

I'm creating a permission system for my cms

 

I have the permissions defined inside my config.php folder.

The defined permissions looks like this:

 

<?php
$permissions = array(
    'faq' => array(
        1 => 'f_view',
        2 => 'f_manage',
        4 => 'f_ask',
    ),
    'page' => array(
        1 => 'p_view',
        2 => 'p_manage_cat',
        4 => 'p_manage_comment',
        8 => 'p_post_page',
        16 => 'p_post_comment',
    ),
    'bug' => array(
        1 => 'b_view',
        2 => 'b_manage_cat',
        4 => 'b_manage_comment',
        8 => 'b_post_issue',
        16 => 'b_post_comment',
    )
)
?>

 

When creating a user group, these permission groups(faq,page,bug) have bitfields, such as(b_manage_cat,b_manage_comment).

 

When you check a box, it sets the bitfields value as true, unchecked, its false.

It then serializes the array, and puts it inside the perms field inside the groups table.

 

I have a screen shot attached to this post of what my $_SESSION global contains, below it, is the unserialized content of the perms group contains.

 

What I want to do, is add the unserialized array into the perms session data.

 

But what I am having trouble with, is that itself.

 

This is the code I use, to set the set the perm groups into the session(which is currently not working).

 

<?php
    // for all the permission groups
    foreach( $permissions as $permgroup => $perms )
    {
        // for each item in the bitfield
        foreach( $perms as $bit => $name )
        {
            // if the bit is set for this permission in their usergroup
            if( $user_group[$ugid]['perms'][$permgroup] & $bit )
            {
                // set this permission to true
                $_SESSION["$security_session"]['perms'][$permgroup][$name] = true;
            }
        }
    }
?>

 

What I want, if the permission name is in the unserialized array, and it has the bitfield, you set it to TRUE, but I can't even get to perms to go inside my array.

 

Thanks for any help in advance.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Yes,session_start has been initiated.

Error reporting is on E_ALL, there are no errors.

 

let me post the actual function i'm using:

<?php
function fetch_perms($ugid)
{
  global $user_group,$permissions,$security_session;
  
    // for all the permission groups
    foreach( $permissions as $permgroup => $perms )
    {
        // for each item in the bitfield
        foreach( $perms as $bit => $name )
        {
            // if the bit is set for this permission in their usergroup
            if( $user_group[$ugid]['perms'][$permgroup] & $bit )
            {
                // set this permission to true
                $_SESSION["$security_session"]['perms'][$permgroup][$name] = true;
            }
        }
    }
}
?>

Link to comment
Share on other sites


this is whaat printing $user_group outputs

Array
(
    [type] => pre_defined
    [name] => Administrators
    [description] => 
    [title] => Administrator
    [perms] => Array
        (
            [faq] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

            

 => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

            [bug] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

            [download] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

            [gallery] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

            [shoutbox] => Array
                (
                    [0] => 1
                    [1] => 2
                )

            [poll] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

            [forum] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                    [5] => 6
                    [6] => 7
                    [7] => 8
                )

            [users] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

            [admin] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                )

        )

)

okay, so what im trying to do, is be able to do this,

if ($_SESSION['perms']['forums'][f_can_view] == TRUE)

{ do this }

 

but i might first assign the perms to the session properly

which is what im stuck doing

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.