如何检查“检查”php代码或页面中的权限?
我使用explode和in_array
用户登录并在“检查”页面后,代码必须检查用户是否具有“数据显示”权限..但“检查”页面中的代码不这样做
“检查”页面代码有什么问题
这是我的数据库:
+--------------------+-------------------------------+
| username | user_privilege |
|--------------------|-------------------------------|
| amal |7gz,agt_courses,newbill |
| | |
+----------------------------------------------------+
| | |
| ahmed |dataDisplay,previllige,newUsers|
+----------------------------------------------------+
第一页“登录”php:
<?php
ob_start();
session_start();
include '../connection/connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
if($username && $password ){
$finduser = mysqli_query($link,"SELECT * FROM LOGIN WHERE username = '".$username."' AND password = '".$password ."'") or die("error");
if(mysqli_num_rows($finduser) !=0){
while($row = mysqli_fetch_array($finduser)){
$uname = $row['username'];
$pass= $row['password '];
$arr=explode(",",$row['user_privilege']);
}
}
{
$_SESSION['sessionname'] =$uname;
$_SESSION['sessionpass'] =$password ;
$_SESSION['sessionpre'] =explode(",",$row['user_previllige']);
header ("location:../agtSite/agt2.php");
}
}
ob_end_flush();
?>
第二页“检查”php:
<?php
session_start();
$_SESSION['sessionpre']='';
$haspermission =in_array("dataDisplay",$_SESSION['sessionpre']);
if( $haspermission )
{
header("location: agt2.php");
}
else{header("location: ../display/display.php");}
?>