如何在php中使用标头正确重定向?
我的代码-如何在php中使用标头正确重定向?,php,Php,我的代码- <?php error_reporting(E_ALL); ?> <?php session_start(); if(isset($_POST["subLogin"])) { $uname = trim($_POST["tbUser"]); $pass = $_POST["pasUser"]; if($uname == "") { he
<?php
error_reporting(E_ALL);
?>
<?php
session_start();
if(isset($_POST["subLogin"]))
{
$uname = trim($_POST["tbUser"]);
$pass = $_POST["pasUser"];
if($uname == "")
{
header('Location: index.php?e=1');
}
else if($pass == "")
{
header('Location: index.php?e=2');
}
$unameF = "";
$passF = "";
$userfile = fopen("DB/userDB.txt", "r");
while(!feof($userfile))
{
$arr1 = explode(":", fgets($userfile));
$unameF = trim($arr1[1]);
$arr1 = explode(":", fgets($userfile));
$passF = trim($arr1[1]);
$arr1 = explode(":", fgets($userfile));
$type = trim($arr1[1]);
if($unameF == $uname)
{
$_SESSION["uname"] = $uname;
$_SESSION["type"] = $type;
header('Location: welcome.php');
}
}
header("Location: index.php?e=0");
}
else
{
header('Location: index.php');
}
?>
在这里,“header(“Location:index.php?e=0”);”总是被执行,即使用户名匹配也是如此。而且“welcome.php”永远不会到达。如果“header(“Location:index.php?e=0”);”这一行被注释掉,那么它就可以正常工作。任何解决方案???在重定向后调用exit()
header('Location: index.php?e=1');
exit();
是否尝试退出()?添加
exit代码>在所有头()调用之后。