Php-based permission assignment implementation code

Source: Internet
Author: User

Today, I wrote down my thoughts on how to assign the background administrator permissions.
Copy codeThe Code is as follows: <? Php
/** Reader
* The Idea Of xiaobian is simple to implement.
* The ID number of each topic is fixed and then the Administrator
* After creating an administrator, select the corresponding topic when assigning permissions to the Administrator.
* In this way, the column id is inserted into the database. After the Administrator logs on to the database
* Obtain the topic id that the Administrator should have. The left-side navigation pane is displayed based on the current topic id.
* Check whether the column ID is displayed or not ..
*/
Header ("Content-type: text/html; charset = UTF-8 ");
Error_reporting (E_ERROR );
$ Act = $ _ GET ['ac'];
$ Conn = mysql_connect ('localhost', 'root', 'root ');
Mysql_select_db ('Study ', $ conn );
Mysql_query ('set names utf8 ');
If ($ act = "add") {// here is the method to add
$ Prom = $ _ POST ['prom '];
/*
After obtaining the column id, split the array into strings and insert it to the database.
Because the database does not provide the field type for inserting Arrays
*/
$ Par = implode (',', $ prom );
// Here, the admin user is used as an example.
$ SQL = "insert into rc_admin (admin_name, pres) values ('admin', '$ par ')";
Mysql_query ($ SQL );
If (mysql_insert_id ()> 0 ){
Echo "success ";
} Else {
Echo "error ";
}
}
?>
<Form method = "post" action = "index. php? Act = add ">
<Table> <tr>
<Td> headhunting service </td>
<Td> <input name = "prom []" type = "checkbox" id = "prom []" value = "1"/>
Add a headhunting enterprise <br/>
<Input name = "prom []" type = "checkbox" id = "prom []" value = "2"/>
Headhunting enterprises <br/>
<Input name = "prom []" type = "checkbox" id = "prom []" value = "3"/>
Headhunting position <br/>
<Input name = "prom []" type = "checkbox" id = "prom []" value = "4"/>
Enterprise Application (order placement) <br/>
<Input name = "prom []" type = "checkbox" id = "prom []" value = "5"/>
Headhunting application management <br/>
</Td>
</Tr>
<Tr>
<Td> reward recruitment </td>
<Td> <input name = "prom []" type = "checkbox" id = "prom []" value = "6"/>
Add a reward enterprise <br/>
<Input name = "prom []" type = "checkbox" id = "prom []" value = "7"/>
Manage reward companies <br/>
<Input name = "prom []" type = "checkbox" id = "prom []" value = "8"/>
Manage reward positions </td>
</Tr>
</Table>
<Input type = "submit" value = "submit" name = 'sub'>
</Form>

This is the permission assignment page. If this option is selected, it indicates that the Administrator has the permission assigned by the admin)

The navigation bar on the left obtains the cookie of this administrator after an Administrator logs on.

Copy codeThe Code is as follows: // the cookie value obtained after logon.
$ SQL = "select * from rc_admin where adminid = 1 ";
$ Res = mysql_query ($ SQL );
$ List = mysql_fetch_assoc ($ res );
/*
Or use explode to split the data into arrays.
Then, determine whether the column id value is not in the array.
*/
$ Pros = $ list ['pres'];
$ Pros = explode (',', $ pros );

// Use the in_array () function to determine if the column id is not in the $ pros field and is not displayed.

<Table width = "146" border = "0" cellspacing = "0" align = "center" cellpadding = "0" class = "leftmenulist" style = "margin-bottom: 5px; ">
<Tr class = "leftmenutext"> <td> <a href = "###" onclick = "collapse_change (6)">
</a> <a href = "###"> reward recruitment </> </td> </tr>
<? If (in_array (6, $ pros) {?>
<Tr> <td> <a href = "admincp. php? Action = reward_add "target =" main "> Add a reward enterprise </a> </td>
</Tr>
<?
}
?>
<? If (in_array (7, $ pros) {?>
<Tr> <td> <a href = "admincp. php? Action = reward_manage "target =" main "> manage reward companies </a> </td>
</Tr>
<?
}
?>
<? If (in_array (8, $ pros) {?>
<Tr> <td> <a href = "admincp. php? Action = bizcate_manage "target =" main "> manage reward positions </a> </td>
</Tr>
<?
}
?>
</Table>

This is the navigation bar on the left.


Here, the corresponding topic is displayed based on the Administrator's logon permissions ..

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.