0

I have a simple code:

header("Location: http://www.wp.pl/");

end this code return:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/plik.php:1) in /var/www/plik.php on line 2

I don't have any BOM, whitespaces etc. before "php" declaration.

What's wrong?

ircmaxell
  • 163,128
  • 34
  • 264
  • 314
oski225
  • 122
  • 2
  • 10
  • 2
    Are you *absolutely sure* there's neither BOM nor whitespace - have you checked with a hex editor or something like that? The warning message clearly states the output was started on the line before the `header` call, so BOM or whitespace is very, very likely to be the real problem. – Michael Madsen Oct 11 '10 at 18:38
  • I'd bet on a doctype declaration before the ` – mario Oct 11 '10 at 18:42
  • I change my editor to notepad++, and everything is ok. Before I use Dreamweaver CS5. Thanks for answer. – oski225 Oct 11 '10 at 18:49

3 Answers3

2

Clearly, you do have something sent already, but you can get around this by wrapping the PHP script in ob_start() / ob_end_flush().

John Franklin
  • 4,962
  • 1
  • 23
  • 27
0

1) Is that the only content on your page?
2) Is that script being included on a different page?
This warning is because when you write anything to the file, that is not the header, you cannot write to the header anymore. The header tells the script where to put its output, and if the header has been modified after content is written, then there is not guarantee of where it should put that content (as I understand it)
If this is not the only content on the page, check if anything above it is throwing an error or displaying anything.
If this is being included on a different page, check if that other page might be displaying something or throwing a warning/error.

chustar
  • 12,225
  • 24
  • 81
  • 119
0

Double check that there are no spaces or new lines after the closing php tag ?>. If there is, those spaces or new-lines get output to the browser, and since there is already output, you can't modify the header. A good practice is to just never include the closing php tag in your php files to prevent this from happening.

TJ L
  • 23,914
  • 7
  • 59
  • 77