Php background multi-user permission Group ideas and implementation program code. Website development requires the website background. if the background is used, users must be assigned the same role, especially in multi-user systems. for example, if one system requires multiple administrators, the website development requires the website background, and the background should naturally assign users the same roles, especially in the case of multi-user systems. for example, if one system requires multiple administrators, so I want to divide these management items into, edit, friendly connection, and administrator. then we need to have permissions and assign roles. today, let's look at a system I used to do.
First introduce the file,
Adminconfig. php this is the permission configuration for all files in the background system.
Fun. php this is a functional function
Left. php website background loads the corresponding function menu based on the user login ID
Op. php calls adminconfig. php default permission file
Opsava. php saves user permissions into a php file
Now let's take a look at the fun. php file.
The code is as follows: |
|
Function findsub ($ keys, $ userid = 'abc') // This function is important to call user permission information. { Include ('user/'. $ userid.'. php '); Foreach ($ bb as $ key => $ submenu) { Foreach ($ submenu as $ subkey => $ menuitem) { If ($ subkey = $ keys) { Return 1; } } } } // The following is the php permission file for the user. // Write Function cache_write ($ name, $ var, $ values ){ $ Cachefile = 'Op/user/'. $ name.'. php '; $ Cachetext =" "; If (! Swritefile ($ cachefile, $ cachetext )) { Exit ("File: $ cachefile write error ."); } } // Convert an array to a string Function arrayeval ($ array, $ level = 0 ){ $ Space = ''; For ($ I = 0; $ I <= $ level; $ I ++ ){ $ Space. = "t "; } $ Evaluate = "Arrayn $ space (n "; $ Comma = $ space; Foreach ($ array as $ key => $ val ){ $ Key = is_string ($ key )? '''. Addcslashes ($ key, '''). ''': $ key; $ Val =! Is_array ($ val )&&(! Preg_match ("/^ -? D + $/", $ val) | strlen ($ val)> 12 )? '''. Addcslashes ($ val, '''). ''': $ val; If (is_array ($ val )){ $ Evaluate. = "$ comma $ key =>". arrayeval ($ val, $ level + 1 ); } Else { $ Evaluate. = "$ comma $ key => $ val "; } $ Comma = ", n $ space "; } $ Evaluate. = "n $ space )"; Return $ evaluate; } // Write a file Function swritefile ($ filename, $ writetext, $ openmod = 'w '){ If (@ $ fp = fopen ($ filename, $ openmod )){ Flock ($ fp, 2 ); Fwrite ($ fp, $ writetext ); Fclose ($ fp ); Return true; } Else { Exit ("File: $ filename write error ."); Return false; } } ?> |
Admin config. php background permission configuration file, saved as an array
The code is as follows: |
|
$ Menus = array ( 'News' => array ( 'Caption '=> 'Information management ', 'Icon '=> 'admin/icon_15.gif ', 'Sub '=> array ( 'Newsaddtype' => array ('Caption '=> 'Category add', 'URL' => 'news/addtype. php '), 'Newstypemange '=> array ('Caption' => 'Category management', 'URL' => 'news/typemange. php '), 'Newsend' => array ('Caption '=> 'Publish information', 'URL' => 'news/newsend. php '), 'Newmange' => array ('Caption '=> 'infomanagement', 'URL' => 'news/newmange. php '), 'Newscomments' => array ('Caption '=> 'Comment management', 'URL' => 'news/comments. php '), ), ), 'Ask '=> array ( 'Caption '=> 'Survey ', 'Icon '=> 'admin/icon_15.gif ', 'Sub '=> array ( 'Voteadmin _ subject_add' => array ('Caption '=> 'Add voting topic', 'URL' => 'vote/admin_subject_add.php '), 'Voteadmin _ subobject' => array ('Caption '=> 'vote topic management', 'URL' => 'vote/admin_subject.php '), 'Voteadmin _ title_add' => array ('Caption '=>' add a vote question ', 'URL' => 'vote/admin_title_add.php '), 'Voteadmin _ title' => array ('Caption '=> 'vote management', 'URL' => 'vote/admin_title.php '), 'Voteadmin _ question_add' => array ('Caption '=> 'Add voting response', 'URL' => 'vote/admin_question_add.php '), 'Voteadmin _ question '=> array ('Caption' => 'vote management', 'URL' => 'vote/admin_question.php '), 'Voteadmin _ system' => array ('Caption '=> 'voting initial configuration', 'URL' => 'vote/admin_system.php ') ), ), 'Analytics' => array ( 'Caption '=> 'ad management ', 'Icon '=> 'admin/icon_15.gif ', 'Sub '=> array ( 'Ada' => array ('Caption '=> 'Add ads', 'URL' => 'Ada. php '), 'Adm '=> array ('Caption' => 'ad management', 'URL' => 'adm. php '), 'Flashadd' => array ('Caption '=> 'Add focus image ad add', 'URL' => 'flashadd. php '), 'Flashad' => array ('Caption '=> 'focus graph ad management', 'URL' => 'flashad. php ') ), ), 'Mange' => array ( 'Caption '=> 'system Postmaster ', 'Icon '=> 'admin/icon_15.gif ', 'Sub '=> array ( 'Adminuser' => array ('Caption '=> 'Add Postmaster', 'URL' => 'adminuser. php '), 'Modpass' => array ('Caption '=> 'password', 'URL' => 'modpass. php ') ), ), ); ?> |
The left. php file is easy to read based on the user's logon ID.
The code is as follows: |
|
$ Userid = $ _ SESSION ['adminid']; Include ("op/admincofig. php "); Include ("op/user/". $ userid. ". php "); Foreach ($ bb as $ key => $ submenu) { Echo" |
Nr". $ Menus [$ key] ['Caption ']."
|
Nr
"; Foreach ($ submenu as $ subkey => $ menuitem) { $ Tmparr = explode ("|", $ menuitem ); Echo "4". $ tmparr [0]." Nr "; } Echo" |
Nr ";}
The op. php file is to call our adminconfig. php file, and then use the function in the fun. php file to save the provided data as an array.
Click save and we call the opsava. php file. the code is as follows:
The code is as follows: |
|
Include ("op/fun. php "); If ($ _ POST) { $ Sarray =$ _ POST; Cache_write ($ userid, 'BB ', $ sarray); // write cache Echo "script" alert ('edited and saved successfully! '); Location = 'Op. php? Userid = ". $ userid." '; script "; } ?> |
After the file is successfully saved, the file content is shown in figure
The code is as follows: |
|
$ Bb = Array ( 'Member' => Array ( 'User _ search' => 'Member upgrade management | user_search.php' ), 'Membercy '=> Array ( 'Cyuser _ search' => 'Member upgrade management | cyuser_search.php ', 'Cyuser _ search5' => 'dating member | cyuser_search.php? Grade = 5' ), 'Userid' => 7, 'Button '=> 'Save editor' ) ?> |
In this case, we only need to load the 7. php file on the left side to display the file here, so that a basic background permission is complete.
Original site original tutorials reprinted with the source: http://www.bkjia.com/phper/php.html
...