错误:“无法修改标头信息 - 标头已由 .. 发送.".


Error: "Cannot modify header information - headers already sent by ...."

我正在开发一个网站,我购买了MAMP PRO。当我尝试通过login_user.php登录时:

if (empty($_POST)===false){
$username = $_POST['username'];
$password = $_POST['password'];

if (empty($username) === true || empty ($password) === true){ 
    $errors[] = 'You need to enter a username and password';
} else if (user_exists($username) === false){
    $errors[] = 'we can''t find that username. have you registered?';
}else if (user_active($username) === false){
    $errors[] = 'you haven''t activated your account!';
}else {
$login = login($username, $password);
if ($login === false){
    $errors[] = 'username/password combination is incorrect!';
}else {
   //set user session 
$_SESSION['user_id'] = $login;
//redirect user to home
header('Location: home.php');
exit();
    }
    }
print_r($errors);
    }
     ?>

用户应重定向到主页.php。

它曾经在我

以前使用的服务器上完美运行,但现在当我在本地机器上测试它时,我只得到一个白页(它基本上停留在login_user.php上)。与数据库的连接工作正常。标头在 MAMP 上是否正常工作?我可以设置会话并在注销中销毁它.php但是两个文件在设置或销毁会话后都不会重定向。有什么线索吗?

更新:我收到此错误:

Warning: Cannot modify header information - headers already sent by (output started at   /Applications/MAMP/htdocs/mywebsite/core/database/databaseconn.php:2) in /Applications/MAMP/htdocs/mywebsite/login_user.php on line 26

修复了它!!问题是在 databaseConn 中.php我在<?php
之前将第一行留空我真不敢相信。;-)

问题是在databaseconn中.php我在<?php之前将第一行留空 您可能希望参考此链接:"php-header-redirect-not-work"