php中的Header()不起作用



我利用PHPheader()函数开发了一个php web应用程序。例如,当用户登录时,网站应该重定向到主页。在使用xampp服务器测试我的本地计算机上的网站时,这可以完美地工作,但是当我尝试使用其域名访问该网站时,它不会重定向到主页。

这是我使用的代码:

$query = "select * from user where email= '$email' and pass= '$pass'";
$result = mysql_query($query);
if(mysql_num_rows($result) != 0) {
       $row = mysql_fetch_row($result);
       $_SESSION['user'] = $row[0];
       $_SESSION['email'] = $row[1];
       $_SESSION['pass'] = $row[2];
       $_SESSION['id'] = $row[3];
       $_SESSION['last_name'] = $row[4];
       $_SESSION['dp'] = $row[5];
       header("Location: index.php");
} else
    $wrong_cred = true;
}
if($wrong_cred) {
    echo("<div class='pageBegin'><p><h1>Wrong User name or Password></h1></p></div>");
}

使用@obstart或尝试使用Java Script

把你的obstart();放在你的页面顶部

if ((isset($_POST['cancel'])) && ($_POST['cancel'] == 'cancel'))
{
    header('Location: page1.php');
    exit();
}

如果使用Javascript使用window.location.href

window.location。href的例子:

 if ((isset($_POST['cancel'])) && ($_POST['cancel'] == 'cancel'))
    {
        echo "<script type='text/javascript'>window.location.href = 'page1.php';</script>"
        exit();
    }

最新更新