Php background multi-user permission Group ideas and implementation program code sharing _ php instances

Source: Internet
Author: User
Tags php website
Many times, we need to take into account the permissions of multiple users during the development process. in this article, you can refer to adminconfig. php, which is the configuration of all file permissions 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/www.hzhuti.com/'.w.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/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 ";
}


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.

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.