具有标头功能的重定向无法工作,但没有错误



我正在尝试在保存会话的日志记录后重定向用户。我正在尝试使用PHP中的头函数:

<?php
include 'phpconnect.php';
if(isset($_POST['but_submit'])){
$uname = mysqli_real_escape_string($conn,$_POST['txt_uname']);
$password = mysqli_real_escape_string($conn,$_POST['txt_pwd']);
if ($uname != "" && $password != ""){
$sql_query = "select count(*) as cntAdmin from admindb where adminID='".$uname."' and AdminPassword='".$password."'";
$result = mysqli_query($conn,$sql_query);
$row = mysqli_fetch_array($result);
$count = $row['cntAdmin'];
if($count > 0){
$_SESSION['uname'] = $uname;
header('Location: adminpanel.php');
}else{
die("Invalid username and password");
}
}
}
?>

凭据是正确的,所有其他功能(例如向数据库中输入一些数据的注册表(都在工作。如果凭据错误,则回显函数调用工作正常,因此数据库连接正常。我想是头出了什么问题,但不知道。

尝试这个

header("Location: /adminpanel.php");

作为最后的手段,你可以使用这个

echo "<script>";
echo "window.location.href='/adminpanel.php'";
echo "</script>";

相关内容

最新更新