tags:

views:

67

answers:

3

hi,

I modified a very simple php page on my server:

<?php
   header("Location:http://www.google.com");
?>

and it stopped to work. I get as result a blank page (Without source in it).

I modified back to the previous url.. and it still doesn't work.

What's going on ?

Thanks

+4  A: 
<?php <-- check for whitespace before this (by popular demand)
   error_reporting(E_ALL); // report all error messages
   header("Location: http://www.google.com"); // leave a space between name and value
?> <-- remove this, or check for whitespace after it

My thinking is, there's a renegade whitespace character after your final closing tag or before the opening one.

karim79
what's wrong with whitespace you mention here?
Col. Shrapnel
I think, too, that additional whitespace shouldn't be an error, unless it came from some previously included PHP file, which is not the case.
Boldewyn
@Col. Shrapnel - http://stackoverflow.com/questions/1656744/when-not-to-close-a-php-file/, @Boldewyn - I reckon it's worth a try.
karim79
I think whitespace after the closing tag wouldn't be a problem here. Before the opening tag however, it will.
Lex
I threw that in guys. There, I think it's all covered now.
karim79
I don't need references to any questions, because I **know** how it work. there is nothing bad in spaces or whatever characters being sent **after** header.
Col. Shrapnel
@Col. Shrapnel - I didn't realise that, which is why I gave you the reference. It certainly was not to patronize you. Peace.
karim79
Indeed "removing the white space" was the solution. Error reporting was not working on that server (I guess because of php configuration). I can't believe I lost 1h on it, and this was the problem.
Patrick
@Patrick - was the whitespace at the beginning or end?
karim79
BOth at the beginning and at the end... But it is strange because I tested the php code with echo "test"; and the text was correctly printed. Only the header function doesn't work if you leave space outside php tags.
Patrick
+1  A: 

You have saved it with utf8 format. Save file as utf8 without bom or ansi, then it should work.

hey
Oh, yes. Good idea, the infamous BOM could be the reason.
Boldewyn
A: 

The problem could happen if you are printing something in this page before header. Or sometimes I had the same problem when I had UTF-8 encoding for the page which has header.

Bakhtiyor