Skepsis Posted June 15, 2009 Share Posted June 15, 2009 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 More sharing options...
GingerRobot Posted June 15, 2009 Share Posted June 15, 2009 1.) Do you have session_start at the top of your page? 2.) Do you have all errors turned on and display errors on? If you're not sure, add these to the top of your script: ini_set('display_errors','On'); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/162218-array-help/#findComment-856102 Share on other sites More sharing options...
Skepsis Posted June 15, 2009 Author Share Posted June 15, 2009 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 More sharing options...
pdkv2 Posted June 15, 2009 Share Posted June 15, 2009 try printing $user_group in the function i doubt if this array is empty ? Link to comment https://forums.phpfreaks.com/topic/162218-array-help/#findComment-856106 Share on other sites More sharing options...
Skepsis Posted June 15, 2009 Author Share Posted June 15, 2009 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 More sharing options...
Skepsis Posted June 15, 2009 Author Share Posted June 15, 2009 can i have a bump since my topic got knocked down to the end of the list? Link to comment https://forums.phpfreaks.com/topic/162218-array-help/#findComment-856203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.