第七十八天上课 PHP权限控制
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第七十八天上课 PHP权限控制相关的知识,希望对你有一定的参考价值。
ShenfenGuanLi
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../ZZ-function/js/$Jquery.js"></script> <title>无标题文档</title> <br> <div>请选择用户: <select> <?php include"../ZZ-function/class/uniondatabase.php"; $db=new unionDatabase(); $sql="select ZhangHu,MingZi from yonghu"; $result=$db->query($sql); foreach($result as $i) { echo"<option value=‘$i[0]‘>$i[1]</option>"; } ?> </select> </div> <div><br>请选择职务: <?php $sql="select * from juese"; $result=$db->query($sql); foreach($result as $i) { echo"<input class=‘JueSe‘ type=‘checkbox‘ value=‘$i[0]‘>$i[1]"." "; } ?> </div><br /> <div><input id="TiJiao" type="button" value="确定"/></div> <script type="text/javascript"> $(document).ready(function() { JueSe(); $("select").change(function() { JueSe(); }); $(‘#TiJiao‘).click(function() { JueSeTiJiao(); }) }); function JueSe() { var ZhangHu=$(‘select‘).val(); $.ajax ({ url:"JueSe.php", data:{ZhangHu:ZhangHu,X:1}, type:"POST", dataType:"JSON", success: function(e) { var JueSe=$(‘.JueSe‘); JueSe.prop(‘checked‘,false) for(var i=0;i<JueSe.length;i++) { var j=JueSe.eq(i).val(); for(var x=1;x<e.length;x++) { if(e[i][0]==j) { JueSe.eq(i).prop(‘checked‘,true); } } } } }); } function JueSeTiJiao() { var ZhangHu=$(‘select‘).val(); var JueSeX=$(‘.JueSe‘); var JueSe=‘‘; for(var i=0;i<JueSeX.length;i++ ) { if(JueSeX.eq(i).prop(‘checked‘)) JueSe+=JueSeX.eq(i).val()+"|"; } JueSe=JueSe.substr(0,JueSe.length-1); $.ajax ({ url:"JueSe.php", data:{ZhangHu:ZhangHu,JueSe:JueSe,X:2}, type:"POST", dataType:"TEXT", success: function(e) { alert(e) } }); } </script>
JueSe.php
<?php include"../ZZ-function/class/uniondatabase.php"; $db=new unionDatabase(); $x=$_POST[‘X‘]; if($x==1) { $ZhangHu=$_POST[‘ZhangHu‘]; $sql="select JueSe from yonghuInjuese where ZhangHu=‘$ZhangHu‘"; echo $db->queryJson($sql); } else if($x==2) { $ZhangHu=$_POST[‘ZhangHu‘]; $JueSe=$_POST[‘JueSe‘]; $sql="delete from yonghuInjuese where Zhanghu=‘$ZhangHu‘"; $result1=$db->query($sql); $JueSe=explode("|",$JueSe); foreach($JueSe as $i) { $sql="insert into yonghuInjuese values(‘‘,‘$ZhangHu‘,‘$i‘)"; $result2=$db->query($sql); } if($result1||$result2) echo"角色修改成功"; else echo"修改失败"; }
DengRu.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>登入界面</title> <style> *{outline:none;} form { text-align:center; top:20px; } form input { border:1px solid #0F0; } </style> <?php session_start(); if(!empty($_POST[‘submit‘])) { if(empty($_POST[‘ZhangHu‘])||empty($_POST[‘MiMa‘])) { echo"<script>alert(‘账户或密码不能为空‘)</script>"; } else { $ZhangHu=$_POST[‘ZhangHu‘]; $MiMa=$_POST[‘MiMa‘]; include"../ZZ-function/class/uniondatabase.php"; $db=new unionDatabase(); $sql="select count(*) from yonghu where ZhangHu=‘$ZhangHu‘ and MiMa=‘$MiMa‘"; if($db->queryStr($sql)==1) { $_SESSION[‘ZhangHu‘]=$ZhangHu; header(‘location:main.php‘); } } } ?> <form action="" method="post"> <h1>登入</h1> <div>账 号: <input type="text" name="ZhangHu"/></div><br> <div>密 码: <input type="password" name="MiMa"/></div><br> <div> <input type="submit" name="submit" value="登入"/> <input type="button" value="复位"/> </div><br> </form>
main.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>主界面</title> <?php session_start(); if(empty($_SESSION[‘ZhangHu‘])) { header(‘location:DengRu.php‘); } include"../ZZ-function/class/uniondatabase.php"; $db=new unionDatabase(); $ZhangHu=$_SESSION[‘ZhangHu‘]; $sql="select JueSe from yonghuinjuese where ZhangHu=‘$ZhangHu‘"; $JueSe=$db->query($sql); $QuanXian=array(); foreach($JueSe as $i) { $sql="select QuanXian from jueseinquanxian where JueSe=‘$i[0]‘"; $result=$db->query($sql); foreach($result as $j) { array_push($QuanXian,$j[0]); } } $QuanXian=array_unique($QuanXian); echo"<ul>"; foreach($QuanXian as $i) { $sql="select Name from quanxian where DaiHao=‘$i‘"; $j=$db->queryStr($sql); echo"<li>$j</li>"; } echo"</ul>"; ?>
以上是关于第七十八天上课 PHP权限控制的主要内容,如果未能解决你的问题,请参考以下文章
第六十八天上课 jquery( josn )和( ajax )