Php implements simple permission management sample code and permission management sample code
Today, we mainly implement a permission management system to set different permissions for different users, so that users with different permissions can use different functions after logon. First, let's take a look at the database.
A total of five tables, qx_user, qx_rules, and qx_juese, form a "w" relationship with the other two tables, which is also a common method of permission database, first, Set permissions first, that is, the management layer sets different permissions for different users.
Guanli. php
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Chuli. php
<?phpinclude("../../fengzhuang/DBDA.class.php");$db = new DBDA();$type = $_POST["type"];switch($type){ case 0: $uid = $_POST["uid"]; $sql = "select jueseid from qx_uij where useid='{$uid}'"; echo $db->StrQuery($sql); break; case 1: $uid = $_POST["uid"]; $juese = $_POST["juese"]; $sdel = "delete from qx_uij where useid='{$uid}'"; $db->Query($sdel,0); $arr = explode("|",$juese); foreach($arr as $v) { echo $v; $sql = "insert into qx_uij values('','{$uid}','{$v}')"; $db->Query($sql,0); } echo "OK"; break;}
Effect ,:
I can select which user to set permissions for and what role to give to, which can be one or more. Click OK to grant this permission to the database.
For example, Ma Qi has two roles, foreground and market.
Now, delete the front-end and add Finance
Let's see if the database has been added
Maqithat item has been changed, j003 and j004 are the market and financial roles.
Next, log on to an account and view its functions.
Login. php
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Logincl. php
<?phpsession_start();include("../../fengzhuang/DBDA.class.php");$db = new DBDA();$uid = $_POST["uid"];$pwd = $_POST["pwd"];$sql="select pwd from qx_user where uid='{$uid}'";$mm = $db->StrQuery($sql); if($mm==$pwd && !empty($pwd)){ $_SESSION["uid"]=$uid; header("location:main.php");}
Main. php
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Effect ,:
Shows that Li Si's functions are:
Check whether the database is the same:
The results are the same. This completes permission management.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.