PHP background Multi-user rights group ideas and Implementation program code sharing _php Tutorial

Source: Internet
Author: User
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.
Copy CodeThe code is as follows:
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;
}
}
}
}
The following is a PHP permission file that generates a user
Write
function Cache_write ($name, $var, $values) {
$cachefile = ' op/www.hzhuti.com/'. $name. PHP ';
$cachetext = " ";
if (!swritefile ($cachefile, $cachetext))
{
Exit ("File: $cachefile write error.");
}
}
Arrays 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 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 CodeThe code is 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 ' = ' 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 CodeThe code is as follows:
$userid = $_session[' Adminid ');
Include ("op/admincofig.php");
Include ("op/www.hzhuti.com/". $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
Copy the Code code as follows:
Include ("op/fun.php");
if ($_post)
{
$sarray = $_post;
Cache_write ($userid, ' BB ', $sarray);//write Cache
echo "";
}
?>

After saving successfully, the contents of the file
Copy the Code code 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 ' = ' 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.

http://www.bkjia.com/PHPjc/324983.html www.bkjia.com true http://www.bkjia.com/PHPjc/324983.html techarticle adminconfig.php This is the configuration of all file permissions in the background system. Fun.php This is a functional function left.php site background based on the user login ID to load the corresponding function menu op.ph ...

  • Related Article

    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.