【发布时间】:2012-07-21 20:45:14
【问题描述】:
我在运行用户登录脚本后尝试重定向时收到此错误。
它试图在这一行更改标题数据:
header("Refresh: 2; url=index.php");
这是完整的 login.php 脚本。
<?php
session_start();
require_once('init.php');
$username = trim($_POST['username']);
// create a new object
$login = new Auth($_POST, $dbh);
if($login->validateLogin()){
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$list = $login->getUserInfo();
$_SESSION['id'] = $list['id'];
$_SESSION['thumb'] = $list['img_thumb'];
echo '<div class="content">';
echo '<h1>Thank you for logging in '.$username.'. Redirecting...</h1>';
echo '</div>';
header("Refresh: 2; url=index.php");
}else{
echo '<div class="content">';
echo '<h1>Sorry but we didn\'t recognise those login details, please try again.</h1>';
echo '</div>';
}
require_once('inc/footer.inc.php');
?>
init.php 文件调用包含 html5 文档类型、元标记等的 header.php。
如何在用户登录后将用户重定向到索引页面并像往常一样发送标题信息?
【问题讨论】:
-
header('Location:index.php');
-
我希望重定向延迟。另外,使用位置也会出现同样的错误。
-
Location 标头采用绝对 URI,而不是相对 URI(即使大多数浏览器都会出错)。
-
@crm — 良好的经验法则:要么在用户单击链接向前移动之前值得显示消息,要么根本不值得显示。