如何修复“警告:无法修改标题信息”错误?

时间:2012-11-09 14:51:37

标签: php html header warnings

  

可能重复:
  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开始的行。

5 个答案:

答案 0 :(得分:0)

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

之前将空格作为html重新填充空格

答案 1 :(得分:0)

在您完成任何事情后,您无法发送标题。如果放置在第1行使用的标题功能,问题就解决了;)。

答案 2 :(得分:0)

问题是,在执行

之前,您已将数据发送到浏览器
    <?php echo '<?xml version="1.0" encoding="utf-8"?>' ?>

你可以获得E_NOTICE或E_WARNING。您是否尝试过激活错误报告?

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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

(如果你使用php frameworks == true)
{
当您在控制器中有一些输出(如示例echo)时,可能存在这种情况 }

相关问题