繁体   English   中英

创建管理员页面,以便用户无法访问其他页面

[英]creating an admin's page so that the user can not access other pages

我一直在关注有关如何在php和mysql中创建登录和注销页面的在线教程,这似乎很容易,直到我登台要修改脚本的位置时,我才尝试将管理员页面放在用户将有权访问某些链接。.i在我的用户表中添加了一个名为user_level的列,我希望当用户登录时,他的user_level为1时,他将访问season.php脚本中的链接,但是如果他的user_level为2,则他将被定向到另一个页面...我尝试在下面执行此操作,但无法正常工作

if($user_level == 1){

header("Location: links.php");

}
else($user_level == 2){

header("Location: client.php");

}

这是我的session.php代码

<?php

if(!isset($_SESSION['name'])&&isset($_COOKIE['testsite'])){
    $_SESSION['name'] = $_COOKIE['testsite'];
}

$dir = "profiles/".$_SESSION['name']."/images/";
$open = opendir($dir);

while(($file = readdir($open)) != FALSE){
    if($file!="."&&$file!=".."&&$file!="Thumbs.db"){
        echo "<img border='1' width='70' height='70' src='$dir/$file'>";
    }

}

echo "&nbsp<b>".$_SESSION['name']."</b>'s session<br /><a href='logout.php'>Logout</a>";

if($user_level == 1){

header("Location: links.php");

}
else($user_level == 2){

header("Location: client.php");

}
?>

您的语法错误,如果要显示链接,则不应重定向,它应该类似于:

if($user_level == 1){
  // don't redirect here
  include "links.php";
}
// check the php manual for the correct usage of if / else / elseif
elseif ($user_level == 2){
  header("Location: client.php");
  // terminate the script
  exit;
}

另外,使用header("Location: client.php"); 确保这是脚本中的第一件事。 您不能转储整个html页面,然后将其放在底部,它不会重定向。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM