簡體   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