login.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <h1>登录页面</h1> <form action="logincl.php" method="post"> <input type="text" name="uid" /> <input type="password" name="pwd" /> <input type="submit" value="登录" /> </form> </body> </html>
logincl.php
<?php
session_start();
include("../../fengzhuang/DBDA.class.php");
$db = new DBDA();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$sql="select pwd from qx_user where uid='{$uid}'";
$mm = $db->StrQuery($sql);
if($mm==$pwd && !empty($pwd))
{
$_SESSION["uid"]=$uid;
header("location:main.php");
}
main.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h1>主页面</h1>
<?php
session_start();
include("../../fengzhuang/DBDA.class.php");
$db = new DBDA();
if(empty($_SESSION["uid"]))
{
header("location:login.php");
exit;
}
//登录者用户名
$uid = $_SESSION["uid"];
//根据用户名查角色
$sjs = "select jueseid from qx_uij where useid='{$uid}'";
$ajs = $db->Query($sjs);
//定义一个存放功能代号的数组
$arr = array();
//根据角色代号查功能代号
foreach($ajs as $vjs)
{
$jsid = $vjs[0]; //角色代号
$sgn = "select ruleid from qx_jwr where jueseid='{$jsid}'";
$strgn = $db->StrQuery($sgn);
$agn = explode("|",$strgn);
foreach($agn as $vgn)
{
array_push($arr,$vgn);
}
}
//去重,显示
$arr = array_unique($arr);
foreach($arr as $v)
{
$sql = "select * from qx_rules where code='{$v}'";
$attr = $db->Query($sql);
$attr[0][0]; $attr[0][1];
echo "<div code='{$attr[0][0]}'>{$attr[0][1]}</div>";
}
?>
</body>
</html>
完成的效果,如图:

显示李四的职能是:

看看数据库的是不是一样的:


发现结果是一样的。这样权限管理就做完了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。