PHP Language-Permissions

Source: Internet
Author: User
Tags explode php language

Rights Management Page body>

Please select User:<select id= "user" &GT;&LT;?PHPinclude("dbda.php");$db=NewDbda ();$sql= "SELECT * from Users";$attr=$db->query ($sql); for($i= 0;$i<Count($attr);$i++){Echo"<option value= ' {$attr[$i][0]} ' >{$attr[$i][2]}</option> "}?></select></div><div> Please select the role: &LT;/DIV&GT;&LT;DIV&GT;&LT;?PHP$SQLJ= "SELECT * FROM Juese";$ATTRJ=$db->query ($SQLJ); for($i= 0;$i<Count($ATTRJ);$i++){ Echo"<input class= ' js ' type= ' checkbox ' value= ' {$ATTRJ[$i][1]} '/>{$ATTRJ[$i][1]}&AMP;NBSP ";}? ></div><div><input id= "Sure" type= "button" value= "OK"/></div></body>

<script type= "Text/javascript" >

$ (document). Ready (function (e) {

Showjs ();

$ ("#user"). Change (function () {
Showjs ();
})

$ ("#sure"). Click (function () {

var uid = $ ("#user"). Val ();

var js= "";


var cks = $ (". js");

for (Var i=0;i<cks.length;i++)
{
if (Cks.eq (i) [0].checked)
{
Js=js+cks.eq (i). Val () + "|";
}
}
JS = Js.substr (0,js.length-1);

$.ajax ({
URL: "add.php",
DATA:{UID:UID,JUESE:JS},
Type: "POST",
DataType: "TEXT",
Success:function (data) {

alert (data);

}

});

})

function Showjs ()
{
var uid = $ ("#user"). Val ();

$.ajax ({
URL: "juesechuli.php",
Data:{uid:uid},
Type: "POST",
DataType: "TEXT",
Success:function (data) {

var ck = $ (". js");
for (Var j=0;j<ck.length;j++)
{
Ck.eq (j). Removeattr ("checked");
}

if (Data.trim () = "") //trim () Remove space
{
var hang = data.split ("|");
for (var i =0;i{
var lie = hang[i].split ("^");

var ck = $ (". js");

for (Var j=0;j<ck.lenght;j++)
{
if (Ck.eq (j). Val () ==lie[2])
{
Ck.eq (j). Prop ("checked", true);
}
}

}
}

}
});

}

});
</script>

juesechuli.php

<? PHP $uid $_post ["UID"]; include ("dbda.php"); $db New Dbda (); $sql = "SELECT * from Userinjuese where UserId = ' {$uid} '"; Echo $db->strquery ($sql);

add.php

$uid=$_post["UID"];$juese=$_post["Juese"];include("dbda.php");$db=NewDbda ();$sqld= "Delete from Userinjuese where userid= ' {$uid}‘";$db->query ($sqld, 0);$js=Explode("|",$juese);$isok=true; for($i= 0;$i<Count($js);$i++){$sql= "INSERT into Userinjuese values ('", ' {$uid}‘,‘{$js[$i]}‘)";$isok=$isok&&$db->query ($sql, 0);}if($isok){Echo"OK";}Else{Echo"No";}

loginchuli.php

<?PHPSession_Start()$uid=$_post["UID"];$pwd=$_post["PWD"];include("dbda.php");$db=NewDbda ();$sql= "SELECT count (*) from Users where uid= ' {$uid} ' and pwd= ' {$pwd}‘";if($db->strquery ($sql) = = "1"){$_session["UID"]=$uid;Header("location:main.php")}Else{Header("location:login.php");}

main.php

<body><?PHPSession_Start();if(!Empty($_session["UID"])){$uid=$_session["UID"];}Else{Header("location:login.php");}include("dbda.php");$db-NewDbda ();//check roles based on user name$sql= "SELECT * from Userinjuese where userid= ' {$uid}‘";$ATTRJ=$db->query ($SQLJ);//array for storing function codes$attr=Array(); for($i= 0;$i<Count($ATTRJ);$i++){//based on role check function$js=$ATTRJ[$i][2];$SQLR= "Select RuleId from Juesewithrules where jueseid= ' {$js}‘";$STRR=$db->strquery ($SQLR);$ATTRR=Explode("|",$STRR);//merging the arrays$attr=Array_merge($attr,$ATTRR);}//Go heavy$attr=Array_unique($attr);//Check function name according to function code and display in Div for($j= 0;$j<Count($attr);$j++){$SQLG= "Select Name from Rules where code= ' {$attr[$j]}‘";$name=$db->strquery ($SQLG);Echo"<div class = ' Menu ' >{$name}</div> "}?></body>

PHP Language-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.