错误:“无法修改标题信息-...已经发送的标题." [英] Error: "Cannot modify header information - headers already sent by ...."

查看:101
本文介绍了错误:“无法修改标题信息-...已经发送的标题."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing a website and I purchased MAMP PRO. When I try to login through 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);
    }
     ?>

应将用户重定向到home.php.

the user should be redirected to home.php.

它曾经在以前使用过的服务器上运行良好,但是当我在本地计算机上对其进行测试时,我得到的只是一个白页(基本上保留在login_user.php上). 与数据库的连接工作正常.标头在MAMP上正常工作吗?我可以设置会话并在logout.php中销毁它,但是在设置或销毁会话后,两个文件都不会重定向.有任何线索吗?

It used to work perfectly on the server I was using before but now I get just a white page (it stay basically on login_user.php) when I test it on my local machine. The connection to the database works fine. Does Header work properly on MAMP? I'm able to set the session and destroy it in logout.php but both files don't redirect after having set or destroyed the session. Any clue?

更新:我收到此错误:

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
之前的第一行留空 我简直不敢相信. ;-)

FIXED IT!!! the problem was that in databaseconn.php I left blank the first line before <?php
I can't believe it. ;-)

推荐答案

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

the problem was that in databaseconn.php I left blank the first line before <?php you may want to refer to this link: "php-header-redirect-not-working"

这篇关于错误:“无法修改标题信息-...已经发送的标题."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆