-4

Possible Duplicate:
PHP Fix Warning: Cannot modify header information - headers already sent
“Warning: Headers already sent” in PHP

I had a nice website that worked perfectly. The first page is header.php and the first line was:

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

Then one day it started to say parse error line 1. So I did some research on the web and changed the first line into this:

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

And the parse error problem vanished. But then another problem appeared:

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

So I decided to remove this first line from the code (and to be honest I had no idea what was it's purpose). Then a new error appeared :

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

And here's the code where I can't find any error (no blanks at end of lines, for sure)

<!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>
...

The line 25 is the one where the php begins.

Community
  • 1
  • 1
frénésie
  • 1,716
  • 3
  • 16
  • 14

5 Answers5

0

somewhere in your code you are using header() if you output anything before that code your page wil return that error. Plus be certain you have no spaces before <?php and after ?> what will result the page to be reder the space as html before sending the header();

John In't Hout
  • 304
  • 1
  • 10
  • This thing is I don't output anything before the header() and the error says that the outpout happens line 25 or line 1 if i keep my first line (as you can see in the thread). – frénésie Nov 09 '12 at 15:13
0

You cant send the header after you've done anything. If you place the header function you use on line 1, the problem is fixed ;).

e--
  • 198
  • 1
  • 15
0

Well the problem ist you send already data to the browser before you execute

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

may you get an E_NOTICE or E_WARNING. Have you tried to activate error reporting ?

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

The error is inside the php tags, probably you use something like Header Location. In html there is no error.

paulinho
  • 146
  • 8
0

(If you use php frameworks == true)
{
This situation can exists, when you have some output like example echo in controller.
}

Marys
  • 139
  • 4