0

Possible Duplicate:
Headers already sent by PHP

After 2 hours of searching for answers i have still not fixed this problem.

I get Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/public_html/xxx1.php:6) in /home/xxx/public_html/xxx2.php on line 10

What have i done so far?

-Checked for no whitespace, in xxx1 and xxx2. I have just change webhosting and now the problem apperas. It says it the file xxx1 on line 6. Please can any one sort this out? This is the code.

<?php

require_once(__ROOT__.'/config.php');

?><head>
<script src="scripts/func.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/yui.css">
<script src="scripts/yahoo-dom-event.js"></script>
<script src="scripts/element-min.js"></script>
<script src="scripts/container_core-min.js"></script>
<script src="scripts/editor-min.js"></script>
<script src="scripts/func.js" type="text/javascript"></script>
</head>
<?
Community
  • 1
  • 1
inpbox
  • 129
  • 1
  • 1
  • 5

3 Answers3

2

BOM - byte order mark:

make sure this file and config.php are encoded without BOM. in notepad++: go to Encoding -> UTF8 without BOM.

galchen
  • 5,252
  • 3
  • 29
  • 43
2

Your previous host had output buffering configured, your new host does not. This is the reason you are getting the problem.

Assuming the code above is from xxx1, on line 6 you are starting to output data, because the is something outside the <?php ?> tags, which is treated as data to send straight to the browser. Then, later on, on line 10 of script xxx2, there is a call to header(), setcookie() or some other function that is trying to modify the response headers.

You cannot modify the response headers after you have started sending the body, because the headers have already been sent.

You will have to either:

  • Store the HTML from above in a string, and output it after line 10 of xxx2 or
  • Move the call to the function that tries to change the headers to before line 6 of xxx1

Without seeing more code I/we cannot tell you exactly how to do this.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
  • Hmm allright i think i understand, on line 10 in xx2 it looks like this: $hResult = mysql_query("SELECT id,namn,access FROM r_users WHERE sessid = '$sGUID' AND namn='$sNICK'") or die(mysql_error()); – inpbox Sep 06 '11 at 16:55
  • Then you are probably doing something which causes a fatal error, which will in turn try and change the HTTP response code to `500`, which requires modifying the headers. Do you get any other output, or just the error message? – DaveRandom Sep 06 '11 at 17:17
1

maybe in config.php after closer tag ?> space appear or empty line - for php5 < 5.3 this is a problem. Maybe like this

<?php 
//code here
?>
//this may be a space 
// or one more new line

That's why zend code style guide advice not close php tag Example file xxx.php

<?php 
//not closer tag in end of file

In both you can use ob_clean() - and this help you clean buffer and invistigate mistake - try to put it in any line.

ZigZag
  • 539
  • 1
  • 8
  • 19