我正在尝试检查用户表的访问列表中是否存在用户访问过的页面。
像这样我从URL
获取页面名称$q1 = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);
$var1 = "/".$q1;
从数据库中我获取登录用户的页面名称并使用in_array
函数检查页面名称
$m1 = "select pages.page_id, pages.code, pages.page, pages.href, access_level.page_id, access_level.user_id FROM pages INNER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.user_id=".$_SESSION['user_id']."";
//echo $m1;
$m2 = mysqli_query($con, $m1) or die (mysqli_error($con));
while($m3 = mysqli_fetch_array($m2)) {
print_r($m3['href']);
if(in_array($var1, $m3['href'])) {
}
else
{
header("location:no_access.php");
}
}
但我无法弄清楚in_array
的问题是什么,因为所有页面都重定向到no_access.php页面,而且页面内容也没有显示但是显示页面不是正确重定向。
被修改
$q1 = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);
$var1 = "/".$q1;
$m1 = "select pages.page_id, pages.code, pages.page, pages.href, access_level.page_id, access_level.user_id FROM pages INNER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.user_id=".$_SESSION['user_id']."";
//echo $m1;
$m2 = mysqli_query($con, $m1) or die (mysqli_error($con));
while($m3 = mysqli_fetch_array($m2)) {
$href[] = ($m3['href']);
//print_r($href);
//echo basename($_SERVER['REQUEST_URI'])."/".$var1;
if(in_array($var1, $href)) {
header("location:".BASE_URL."".$var1);
}
else
{
header("location:no_access.php");
}
}
答案 0 :(得分:-1)
尝试这样......
$m1 = "select pages.page_id, pages.code, pages.page, pages.href, access_level.page_id, access_level.user_id FROM pages INNER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.user_id=".$_SESSION['user_id']."";
//echo $m1;
$q1 = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);
$ var1 =“/".$ q1;
$ m1 =“select pages.page_id,pages.code,pages.page,pages.href,access_level.page_id,access_level.user_id FROM pages INNER JOIN access_level ON pages.page_id = access_level.page_id WHERE access_level.user_id =” 。$ _ SESSION [ 'user_ID的'] “”。 // echo $ m1;
$m2 = mysqli_query($con, $m1) or die (mysqli_error($con));
while($m3 = mysqli_fetch_array($m2)) {
$href[] = ($m3['href']);
} //close while loop here
//print_r($href);
//echo basename($_SERVER['REQUEST_URI'])."/".$var1;
if(in_array($var1, $href)) {
header("location:".BASE_URL."".$var1);
}
else
{
header("location:no_access.php");
}