5.27 Permission Exercises

Source: Internet
Author: User

Permission Settings page:

Implementation function: Can add or cancel the corresponding functional rights of the user. The code is as follows:

Main Page:

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >Please select User:<select id= "UID" > <?PHPinclude("database.class.php"); $db=Newdatabase (); $sql _users= "SELECT * FROM Users"; $arr _users=$db->query ($sql _users); foreach($arr _users  as $value _users)                 {                    Echo"<option value= ' {$value _users[0]} ' >{$value _users[2]} </option> "; }              ?> </select></div><br/><!--Job Selection--><div>Please select a position:<?PHP$sql _position= "SELECT * FROM Juese"; $arr _position=$db->query ($sql _position); foreach($arr _position  as $value _position)                {                    Echo"<input type= ' checkbox ' class= ' job ' value= ' {$value _position[0]} ' />{$value _position[1]} &nbsp; "; }            ? ></div><br/><div><input type= "button" value= "OK" id= "BTN"/></div></body> $ (document). Ready (function(e) {Job (); $("#uid"). Change (function() {Job (); })    $("#btn"). Click (function ()    {        varUID = $ ("#uid").Val (); varJob = $ (". Job")); varstr = "";  for(vari=0;i<job.length;i++)        {            if(Job.eq (i). Prop ("checked")) ) {str= str + JOB.EQ (i). Val () + "|"; }} str= str.substr(0,str.length-1); //alert (str);$.Ajax ({URL: "Job1cl.php",Data: {UID:UID,JS:STR},type: "POST",DataType: "TEXT",Success:function(d) {if(d.Trim() = = "OK") {alert ("Add Success"); }                    Else{alert ("Add Failed"); }                  }              })                })                                                functionJob () {varUID = $ ("#uid").Val (); $.Ajax ({URL: "Jobcl.php",Data: {Uid:uid},type: "POST",DataType: "TEXT",Success:function(d) {vardata = d.Split("|"); varJob = $ (". Job")); Job. Prop ("Checked",false);  for(vari = 0;i<job.length; i++)                    {                        varValue =job.eq (i).Val (); //alert ($.inarray (Value,data));                        if($.inarray (Value,data)!=-1) {Job. EQ (i). Prop ("Checked",true); }                    }                 }              })    }                });</script>
View Code

User drop-down list processing:

<? PHP $uid $_post [' UID ']; include ("database.class.php"); $db New database (); $sql = "Select Jueseid from Userinjuese where UserId = ' {$uid} '"; $result $db->str_ajax ($sql); Echo $result;
View Code

Permission handling:

<?PHP$uid=$_post[' UID '];$js=$_post[' JS '];//is a stringinclude("database.class.php");$db=Newdatabase ();$arr _job=Explode("|",$js);//splits the string into an array$result=true;//define a variable to determine the result of execution//clear the user's original informationif(!$db->query ("Delete from Userinjuese where UserId = ' {$uid} ' ", 1)){    $result=$result&&false;}//adding new information, looping through the array of well-dividedforeach($arr _job  as $v){    $sql= "INSERT into Userinjuese values ('", ' {$uid}‘,‘{$v}‘) "; if(!$db->query ($sql, 1))    {        $result=$result&&false; }}//determine if Add is successfulif($result){    Echo"OK";}Else{    Echo"NO";}
View Code

Permission set up, you can login to the relevant website, according to their own permissions to display the corresponding content

Example:

The code is as follows:

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >#Menu{width: 100%; Height:150px}.menu1{Width:150px; Height:50px; Background-color:#999;Line-height:50px; Text-align:Center; Border-radius:5px; Color:#FFF;    float:Left ;}. MENU1:hover{Cursor:pointer; Background-color:#F60;}</style>PHPSession_Start();if(Empty($_session[' UID '])){    Header("location:login.php"); Exit;}$uid=$_session[' UID '];&GT;&LT;H1 align= "Center" > main Page if(!Empty($_session[' UID '])) {Echo $_session[' UID '];} ?>nbsp;<div style= "Float:right" ><a href= "login.php" > Exit system </a></div></div><div id= "menu" > <divclass= "MENU1" > Rights Management </div> <?PHPinclude("database.class.php"); $db=Newdatabase (); //Check the role code according to the UID        $sql _actor_id= "Select Jueseid from Userinjuese where UserId = ' {$uid}‘ "; $r _actor_id=$db->query ($sql _actor_id); //Check function ID according to role code          $all=Array();//store all feature IDs         foreach($r _actor_id  as $value _actor_id)         {             $sql _rule= "Select RuleId from juesewithrules where Jueseid = ' {$value _actor_id[0]} ' "; $r _rule=$db->query ($sql _rule); foreach($r _rule  as $value _rule)             {                 Array_push($all,$value _rule[0]); }             $all=Array_unique($all);//array de-weight         }      //show responsibilities by feature ID       foreach($all  as $value _show)       {         $sql _show= "Select Name from Rules where Code = ' {$value _show}‘"; $r _show=$db->str_ajax ($sql _show); Echo"<div class= ' menu1 ' >{$r _show}</div> "; }      ?></div></body>View Code

5.27 Permission Exercises

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.