tags:

views:

46

answers:

3

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?

A: 

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
+2  A: 

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
A: 

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.

tj111