Web site development must have a website backstage, have the background naturally to the user has the same role to assign, especially the case of multi-user system, such as I a system to have more than one administrator, then I these management to be divided into, edit, friendship Connection, administrator, then we have permission and role assignment, Today, let's look at a system I used to make.
First introduce the file,
Adminconfig.php This is the configuration of all file permissions in the background system.
Fun.php This is a function function
left.php Web site background based on the user login ID to load the corresponding function menu
op.php calling adminconfig.php default permission file
opsava.php Save user Rights into a PHP file
Well, let's take a look at the fun.php file first.
The code is as follows |
Copy Code |
Functions Findsub ($keys, $userid = ' abc ')//This function is important in order to invoke the user's permission information { Include (' user/'. $userid. php '); foreach ($bb as $key = $submenu) { foreach ($submenu as $subkey = $menuitem) { if ($subkey = = $keys) { return 1; } } } } //To generate the user's PHP permissions file //write Function Cache_write ($name, $var, $values) { $cachefile = ' op/user/'. $name. PHP '; $cachetext = "!--? phprn". $ '. $var. ' = '. Arrayeval ($values). " RN?--> "; if (!swritefile ($cachefile, $cachetext)) { Exit ("File: $cachefile write error."); } } //array converted to 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 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; } } ?> |
adminconfig.php Background permissions configuration file, saved as an array
The code is as follows |
Copy Code |
$menus = Array ( ' News ' = Array ( ' Caption ' = ' information management ', ' Icon ' = ' admin/icon_15.gif ', ' Sub ' = = Array ( ' Newsaddtype ' = = Array (' caption ' = ' + ' category added ', ' url ' = = ' news/addtype.php '), ' Newstypemange ' = = Array (' caption ' = ' category management ', ' url ' = ' news/typemange.php '), ' Newsnewsend ' + array (' caption ' = ' release info ', ' url ' = ' news/newsend.php '), ' Newsnewmange ' = = Array (' caption ' = ' information management ', ' url ' = ' news/newmange.php '), ' newscomments ' = = Array (' caption ' = ' review management ', ' url ' = ' news/comments.php '), ), ), ' Ask ' = = Array ( ' Caption ' and ' survey ', ' Icon ' = ' admin/icon_15.gif ', ' Sub ' = = Array ( ' Voteadmin_subject_add ' = = Array (' caption ' + ' Add ' Poll theme ', ' url ' = ' vote/admin_subject_add.php '), ' Voteadmin_subject ' = = Array (' caption ' = ' Manage Poll theme ', ' url ' = ' vote/admin_subject.php '), ' Voteadmin_title_add ' = = Array (' caption ' + ' Add poll question ', ' url ' = ' vote/admin_title_add.php '), ' Voteadmin_title ' = = Array (' caption ' = ' Manage voting issues ', ' url ' = ' vote/admin_title.php '), ' Voteadmin_question_add ' = = Array (' caption ' + ' Add poll answer ', ' url ' = ' vote/admin_question_add.php '), ' voteadmin_question ' = = Array (' caption ' = ' Manage voting answers ', ' url ' = ' vote/admin_question.php '), ' Voteadmin_system ' = = Array (' caption ' = ' voting initial configuration ', ' url ' = ' vote/admin_system.php ') ), ), ' Ads ' = = Array ( ' Caption ' = ' advertising management ', ' Icon ' = ' admin/icon_15.gif ', ' Sub ' = = Array ( ' ada ' + = Array (' caption ' + ' + ' Add ad ', ' url ' = ' ada.php '), ' adm ' + = Array (' caption ' + ' advertising management ', ' url ' = ' adm.php '), ' Flashadd ' = = Array (' caption ' + ' focus map ad add ', ' url ' = ' flashadd.php '), ' Flashad ' = = Array (' caption ' + ' focus map ad management ', ' url ' = ' flashad.php ') ), ), ' Mange ' = Array ( ' Caption ' = ' system Administrator ', ' Icon ' = ' admin/icon_15.gif ', ' Sub ' = = Array ( ' Adminuser ' = = Array (' caption ' = ' admin add ', ' url ' = ' adminuser.php '), ' Modpass ' = = Array (' caption ' = ' password modified ', ' url ' = ' modpass.php ') ), ), ); ?> |
The left.php file is simple enough to read the permission based on the user's login ID.
|
copy code |
"!--? $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";}
op.php This file is to call our adminconfig.php file, and then use the fun.php file function to save the data supplied to the array
Click Save we called the opsava.php file, the code is as follows
The code is as follows |
Copy Code |
Include ("op/fun.php"); if ($_post) { $sarray = $_post; Cache_write ($userid, ' BB ', $sarray);//write Cache echo ""; } ?> |
After saving successfully, the contents of the file
The code is as follows |
Copy Code |
$BB =array ( ' Member ' = Array ( ' User_search ' + ' member upgrade Management |user_search.php ' ), ' Membercy ' = Array ( ' Cyuser_search ' + ' member upgrade Management |cyuser_search.php ', ' Cyuser_search5 ' = ' Friends member |cyuser_search.php?grade=5 ' ), ' UserID ' = 7, ' Button ' = ' Save edit ' ) ?> |
In this case, our left just loads the 7.php file and only shows the file here, so a basic background permission is done.
Original station original tutorial reprint annotated Source: http://www.bkjia.com/phper/php.html
http://www.bkjia.com/PHPjc/444699.html www.bkjia.com true http://www.bkjia.com/PHPjc/444699.html techarticle Web site development without the background of the site, with the background naturally to the user has the same role to assign, especially in the case of multi-user system, such as I a system to have more than one administrator, that ...