1.做一个登录页面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> <form action="loginchuli.php" method="post"> <div>用户名:<input type="text" name="uid" /></div> <div>密码:<input type="password" name="pwd" /></div> <input type="submit" value="登录" /> </form> </body> </html>
2.登录处理页面loginchuli.php
<?php session_start(); include("../DBDA.class.php"); $db = new DBDA(); $uid=$_POST["uid"]; $pwd=$_POST["pwd"]; $sql = "select pwd from users where uid='{$uid}'"; $mm = $db->StrQuery($sql); if($mm==$pwd && $pwd!="") { $_SESSION["uid"] = $uid; header("location:main.php"); } else { echo "登录失败"; } ?>
3.主页面,显示登陆者有的功能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> <style type="text/css"> *{ margin:0px auto; padding:0px} .list{ width:100px; height:35px; background-color:#66C; color:white; text-align:center; line-height:35px; vertical-align:middle; float:left} </style> </head>
<?php session_start(); include("../DBDA.class.php"); $db = new DBDA(); if(empty($_SESSION["uid"]))//防止不经过登录直接打开主页面 { header("location:login.php"); exit; } $uid = $_SESSION["uid"];//用session存登录名 ?>
<body> <div style="width:100%; height:35px">
<?php //根据用户名查角色代号 $sjuese = "select jueseid from userinjuese where userid='{$uid}'";//一个用户名可能对应多个角色代号 $ajuese = $db->Query($sjuese); //根据角色代号查功能 $attr = array(); foreach($ajuese as $v) { $sgn = "select ruleid from juesewithrules where jueseid='{$v[0]}'";//一个角色代号可能对应多个功能,查到这些功能的代号。 $agn = $db->Query($sgn); $attr = array_merge($attr,$agn);//把查到数组就合并在一起 } $attr = array_unique($attr,SORT_REGULAR);//对功能代号进行去重 foreach($attr as $v) { $sname = "select name from rules where code='{$v[0]}'";//根据功能代号查出功能的名字 $name = $db->StrQuery($sname); echo "<div class='list'>{$name}</div>"; } ?>
</div> </body> </html>