标签:
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
<br>
<h1>用户角色:</h1>
<br>
<table border="1" cellpadding="10" cellspacing="2" bordercolor="#3300FF" bgcolor="#CCFF00">
<tr>
<?php
session_start();
$uid = $_SESSION["uid"];//取出用户名代号
echo "<td>{$uid}的权限:</td>";
include("DBDA.class.php");
$db = new DBDA();
//根据用户名,找角色代码
$sql="select * from UserInJueSe where UserId=‘{$uid}‘";
$attr = $db->query($sql);
$qx=array();
foreach($attr as $v)
{
$a = $v[2];//用户的角色,职位
//根据角色代码找权限代码
$sqln ="select RuleId from JueSeWithRules where JueSeId =‘{$a}‘";
$arr = $db->query($sqln);
foreach($arr as $r)
{
array_push($qx,$r[0]);//$qx 是一维数组
}
}
$qx = array_unique($qx);//权限去重复,array_unique()用于一维数组
foreach($qx as $vv)//输出权限代码,对应的权限
{
$rule = "select Name from Rules where Code=‘{$vv}‘ ";
$b=$db->query($rule);
echo "<td>{$b[0][0]}</td>";
}
?>
</tr>
</table>
标签:
原文地址:http://www.cnblogs.com/kevin2016/p/5559423.html