Php background multi-user permission group ideas and implementation program code

Source: Internet
Author: User

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, 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: Copy code

<?
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 = "<? Phprn ". '$'. $ var. '='. arrayeval ($ values)." rn?> ";
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: Copy code

<?
$ 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: Copy code

<?
$ Userid = $ _ SESSION ['adminid'];
Include ("op/admincofig. php ");
Include ("op/user/". $ 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 ";
}

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: Copy code

<?
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: Copy code

<? 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' => '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


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.