PHP background Multi-user rights group idea and implementation program code sharing _php Instance

Source: Internet
Author: User
Adminconfig.php This is the configuration of all file permissions in the background system.
Fun.php This is a functional function
left.php website Background According to the user login ID to load the corresponding function menu
op.php Invoke adminconfig.php default permission file
opsava.php Save user permissions into a PHP file
OK, let's take a look at the fun.php file first.
Copy Code code as follows:

?
function Findsub ($keys, $userid = ' abc ')//It is important 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;
}
}
}
}
The following is a PHP permission file to generate the user
Write
function Cache_write ($name, $var, $values) {
$cachefile = ' op/www.hzhuti.com/'. $name. PHP ';
$cachetext = "<?phprn". $ '. $var. ' = '. Arrayeval ($values). " Rn?> ";
if (!swritefile ($cachefile, $cachetext))
{
Exit ("File: $cachefile write error.");
}
}
Array into strings
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 to 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
Copy Code code as follows:

?
$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 ' => ' classified 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 ' => ' comment management ', ' url ' => ' news/comments.php '),
),
),
' Ask ' => array (
' Caption ' => ' survey ',
' Icon ' => ' admin/icon_15.gif ',
' Sub ' => array (
' Voteadmin_subject_add ' => Array (' caption ' => ' Add voting theme ', ' url ' => ' vote/admin_subject_add.php '),
' Voteadmin_subject ' => Array (' caption ' => ' management voting theme ', ' url ' => ' vote/admin_subject.php '),
' Voteadmin_title_add ' => Array (' caption ' => ' Add voting problem ', ' url ' => ' vote/admin_title_add.php '),
' Voteadmin_title ' => Array (' caption ' => ' management polling question ', ' url ' => ' vote/admin_title.php '),
' Voteadmin_question_add ' => Array (' caption ' => ' Add voting answer ', ' url ' => ' vote/admin_question_add.php '),
' Voteadmin_question ' => Array (' caption ' => ' management vote answer ', ' url ' => ' vote/admin_question.php '),
' Voteadmin_system ' => Array (' caption ' => ' voting initial configuration ', ' url ' => ' vote/admin_system.php ')
),
),
' Ads ' => Array (
' Caption ' => ' ad management ',
' Icon ' => ' admin/icon_15.gif ',
' Sub ' => array (
' Ada ' => Array (' caption ' => ' increased advertising ', ' url ' => ' ada.php '),
' ADM ' => Array (' caption ' => ' ad management ', ' url ' => ' adm.php '),
' Flashadd ' => Array (' caption ' => ' focus map ad increased ', ' 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 modification ', ' url ' => ' modpass.php ')
),
),
);
?>

left.php file is very simple, based on user login ID read out permissions
Copy Code code as follows:

?
$userid = $_session[' Adminid '];
Include ("op/admincofig.php");
Include ("op/www.hzhuti.com/". $userid. ". PHP ");
foreach ($bb as $key => $submenu)
{
echo "<tr><td bgcolor=" #D879A7 "style=" Line-height:22px;text-align:center;color: #ffffff; > Nr <font color= "#EA6A8D" face= "Webdings" ></font><b> ". $menus [$key] [' caption ']." </b><br/></td></tr> nr <tr ><td bgcolor= "F5e8f1" >;
foreach ($submenu as $subkey => $menuitem)
{
$tmparr = Explode ("|", $menuitem);
echo "<font color=" #EA6A8D "face=" webdings ">4</font><a href=". $tmparr [1]. "' target= ' mainframe ' > ' . $tmparr [0]. " </a><br> nr ";
}
echo "</td></tr> nr";
}

op.php This file is to call our adminconfig.php file, and then use the function in the fun.php file to save the supplied data as an array.

Click Save we call the opsava.php file, the code is as follows

Copy Code code as follows:

?
Include ("op/fun.php");
if ($_post)
{
$sarray = $_post;
Cache_write ($userid, ' BB ', $sarray);/write Cache
echo "<script>alert (' Edit save success! '); location= ' op.php?userid= '. $userid. "'; </script> ";
}
?>

After saving successfully, the contents of the file are
Copy Code code as follows:

<?php
$BB =array
(
' Member ' => Array
(
' User_search ' => ' member upgrade Management |user_search.php '
),
' Membercy ' => Array
(
' Cyuser_search ' => ' member upgrade Management |cyuser_search.php ',
' Cyuser_search5 ' => ' friend member |cyuser_search.php?grade=5 '
),
' UserID ' => 7,
' button ' => ' save edit '
)
?>

In this way, our left can only load 7.php files will only show the files here, such a basic background permissions are complete.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.