可能重复:
“Warning: Cannot modify header information - headers already sent by” error
Headers already sent by PHP
我看过许多其他网站,说明问题是因为白色间距。我不认为这是问题,因为我的PHP脚本结束后和我的PHP脚本开始之前我不留任何白色间距。这是完整的错误
:无法修改标题信息 - 第22行的admin / login.php中已经发送的标题(在/admin/login.php:19处开始输出)
这是我的代码:
<?php
require_once("../../includes/database.php");
require_once("../../includes/session.php");
require_once("../../includes/user.php");
if($session->is_logged_in())
{
header("Location:index.php");
}
if(isset($_POST['submit']))
{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
//Check Databases
$found_user = User::authenticate($username, $password);
$found_user->id = $found_user[0];
if($found_user)
{
$session->login($found_user);
header("Location:index.php");
}
else
{
echo "Username/password combination incorrect.";
}
} else { //form is not submitted
$username = "";
$password = "";
}
?>
<html>
<head>
</head>
<body>
<h1>Photo Gallery</h1>
<div id="main">
<h2>Staff Login</h2>
<form action="login.php" method="post">
<table>
<tr>
<td>Username:</td>
<td>
<input type="text" name="username" maxlength="30" value="" />
</td>
</tr>
<tr>
<td> Password:</td>
<td>
<input type="password" name="password" maxlength="30" value="" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value"Login" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php if(isset($database))
{
$database->close_connection();
}
?>
答案 0 :(得分:0)
如果您使用header()
重定向用户,请确保在使用exit()
header()
来电后明确停止脚本。否则,剧本会继续尝试输出所有内容。
例如:
if($session->is_logged_in())
{
header("Location:index.php");
exit();
}