session控制登入权限


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<br><?php
session_start();
if(empty($_SESSION["uid"]))//判断SESSION是不是为空
{
    header("location:EOA.PHP");//为空返回主页
    exit;
}
$uid =$_SESSION["uid"];
require "../class/XiangMu.class.php";
$db = new xiangmu();
$sqlqx = "select Qxian from users where uid ='{$uid}'";//从USERS表中读取权限
$qx =$db->strquery($sqlqx);
$arrqx = explode(',',$qx);//字符串转为数组
$arrurl= array();
foreach($arrqx as $q)
{
    $sqlurl=" select url from quanxian where code = '{$q}' ";//编译字符串用code  查quanxian 表中的url
    $arrurl[]="/EOA/php/".($db->strquery($sqlurl));//拼接地址放入数组中
}
$url= $_SERVER['PHP_SELF'];//获取当前页面的地址
if(!in_array($url,$arrurl))//判断地当前页面是不是在该权限中
{
    header("location:EOA.PHP");//不在的权限跳转到登入页面
    exit;
}
?>

 

posted @   <一>  阅读(1065)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示