2012-11-09 104 views
-4

可能重复:
PHP Fix Warning: Cannot modify header information - headers already sent
“Warning: Headers already sent” in PHP如何解决'警告:无法修改标题信息'错误?

我有一个不错的网站,非常完美。第一页是header.php文件,第一行是:

<?xml version="1.0" encoding="utf-8"?> 

有一天我开始说语法错误行1。所以我做了网络上的一些研究,改变了第一行到这一点:

<?php echo '<?xml version="1.0" encoding="utf-8"?>' ?> 

解析错误问题消失了。但随后另一个问题出现了:

Warning: Cannot modify header information - headers already sent by (output started at /Volumes/raid/Web/Sites/*******.com/header.php:1) 

所以我决定从代码中删除这个第一行(和说实话,我不知道什么是它的目的)。然后,一个新的错误出现:

Warning: Cannot modify header information - headers already sent by (output started at /Volumes/raid/Web/Sites/*******.com/header.php:25) 

这里的地方我找不到任何错误代码(在行尾没有空格,肯​​定)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd"> 
<html lang="fr" dir="ltr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <link href="/css/bootstrap.css" rel="stylesheet"> 
    <link href="/css/style.css" rel="stylesheet"> 
    <link type="image/x-icon" href="./img/lions_icon" rel="icon"> 
    <link type="image/x-icon" href="./img/lions_icon" rel="shortcut icon"> 
    <link href="/css/jquery.ui.all.css" rel="stylesheet"> 
    <title>Lions</title> 
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> 
    <script src="/js/jquery.js"></script> 
    <script src="/js/jquery-1.8.2.js"></script> 
    <script src="/js/jquery.ui.core.js"></script> 
    <script src="/js/jquery.ui.widget.js"></script> 
    <script src="/js/jquery.ui.datepicker.js"></script> 
    <script src="/js/bootstrap.js"></script> 
    <script> 
    $(function() { 
     $("#date").datepicker(); 
     $("#date").datepicker("option", "dateFormat", "yy-mm-dd"); 
     }); 
    </script> 
</head> 
<?php 
// beggining of the php code, 
.... 
?> 
<body> 
... 

线25是一个地方PHP开始。

回答

0

您的代码中的某处正在使用header()如果您在该代码之前输出任何内容,您的页面将返回该错误。另外请确保您在<?php之前和?>之后没有空格,那么在发送header();之前,页面会以html形式返回空格。

+0

这件事是我不输出任何东西之前的头()和错误说输出发生25行或1行,如果我保持我的第一行(你可以看到在线程中)。 –

0

在做任何事情之后,您无法发送标头。如果您放置第1行使用的标题功能,则问题已修复;)。

0

好这个问题您北京时间您执行

<?php echo '<?xml version="1.0" encoding="utf-8"?>' ?> 

可能你获得一个E_NOTICE或E_WARNING前已数据发送给浏览器。您是否尝试激活错误报告?

error_reporting(-1); ini_set('display_errors', 1); 
0

错误是在php标签内,可能你使用的是像Header Location之类的东西。在html中没有错误。

0

(如果你使用的PHP框架==真)
{
这种情况可能存在,当你有一个像例如一些输出呼应控制器。
}

相关问题