权限:查找
用户权限查找:
1,登录用户账号,找到自己的职位代号(角色),
2,根据职位代号找到职位对应的权限代号,查找所有的权限代号,
3,去重,输出代号对应的权限
login.php登录页面:
<body>
<form action="chulilg.php" method="post" >
用户名:<input type="text" name="uid" /><br />
密码:<input type="text" name="pwd" />
<input type="submit" value="提交" />
</form>
</body>
</html>
chulilg.php
<?php
session_start();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$_SESSION["uid"] = $uid;
include("DBDA.class.php");
$db = new DBDA();
$sql = "select count(*) from Users where UserName='{$uid}' and Password='{$pwd}'";
$attr = $db->StrQuery($sql,1);
if($attr == 1)
{
header("location:main.php");
}
else
{
echo "登录失败";
}
?>
main.php
1 <br>
2 <h1>用户角色:</h1>
3 <br>
4 <table border="1" cellpadding="10" cellspacing="2" bordercolor="#3300FF" bgcolor="#CCFF00">
5
6 <tr>
7 <?php
8 session_start();
9 $uid = $_SESSION["uid"];//取出用户名代号
10 echo "<td>{$uid}的权限:</td>";
11
12 include("DBDA.class.php");
13 $db = new DBDA();
14
15 //根据用户名,找角色代码
16 $sql="select * from UserInJueSe where UserId='{$uid}'";
17 $attr = $db->query($sql);
18
19 $qx=array();
20 foreach($attr as $v)
21 {
22 $a = $v[2];//用户的角色,职位
23
24 //根据角色代码找权限代码
25 $sqln ="select RuleId from JueSeWithRules where JueSeId ='{$a}'";
26 $arr = $db->query($sqln);
27
28 foreach($arr as $r)
29 {
30 array_push($qx,$r[0]);//$qx 是一维数组
31 }
32 }
33 $qx = array_unique($qx);//权限去重复,array_unique()用于一维数组
34
35 foreach($qx as $vv)//输出权限代码,对应的权限
36 {
37 $rule = "select Name from Rules where Code='{$vv}' ";
38 $b=$db->query($rule);
39
40 echo "<td>{$b[0][0]}</td>";
41 }
42
43 ?>
44 </tr>
45
46 </table>
结果: