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
https://forums.phpfreaks.com/topic/162218-array-help/
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
https://forums.phpfreaks.com/topic/162218-array-help/#findComment-856104
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
https://forums.phpfreaks.com/topic/162218-array-help/#findComment-856107
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.