tags:

views:

58

answers:

4

I have a single php file, with this code in it:

<?php header("Location: somepage.php"); ?>

Absolutely no spaces before or after the php opening or closing tags and I am getting the

Warning: Cannot modify header information - headers already sent by (output started at C:\ ... \test.php:1

Usually when I get this error, the 1 is the line number of the problem, but in this case line one doesn't have any extra whitespace. I only have this code on the page and I am not including any other files.

I'm using xampp on windows xp. Any ideas what's going on or how I can track down what's really causing the problem.

Thanks

+6  A: 

Chances are that you have what's known as a BOM (Byte Order Mark) in the file. Depending on what editor you're using, you'll need to turn off adding the BOM...

ircmaxell
Thanks for the link @Gordon
ircmaxell
I'm using Komodo Edit, which has never given me a problem before. I did try just using plain old notepad and the I still have the problem.
Joe
Well, the only other thing I can think of would be something to do with `auto_prepend_file`... Have you checked your PHPInfo? Also, you say you tried using notepad, did you write directly in notepad? Or did you copy and paste (since notepad might not display the BOM if it is there, yet it may have been copied)...
ircmaxell
Well, I fixed the problem by just creating a new file and using a different editor (Scite). I just typed the code in and didn't paste it. Now it works fine. It must have been the BOM, like you said. Thanks for your help!
Joe
For Komodo: http://docs.activestate.com/komodo/4.4/prefs.html (there is a preference to disable BOM addition)...
ircmaxell
A: 

If you are sure it is not a BOM causing the error, check your httpd.conf and any .htaccess files if the prepend any other files. Look out for something like this:

<FilesMatch "\.(html?)$">
php_value auto_prepend_file /server/path/to/my/www_root/subdir/file.ext"
</FilesMatch>

Also check your PHP.ini: http://de.php.net/manual/en/ini.core.php#ini.auto-prepend-file

Gordon
A: 

Try to copy / paste your content to another new file using Notepad

Kaaviar
tried this and it didn't work. Still getting the error.
Joe
A: 

Try using WAMP, it doesnt show this error, make sure you donot have spaces before or after the code. For that, if you are using notepad ++ or editplus, go to format and select unix formatting and things should work fine.

OR

try placing this at the top of your page:

<? ob_start(); ?>

then at the bottom of the page place this line of code:

<? ob_flush(); ?> 
Yash
I'm not going to install wamp just for this. Plus, if the error is still there, not fixing it won't help.
Joe
please see the solution posted, that should serve your purpose. And you will never come across this warning again.
Yash
That's not really a fix, but a hack. I would like to fix the problem.
Joe