HTTP redirection using PHP fails when you use UTF-8 encoding
To redirect a page by putting the instruction on the HTTP header, PHP makes it very easy:
<?php
header("Location: http://www.agronesia.net");
?>
The catch to call header successfully is that you must not output anything beforehand. So, no space before the opening PHP tag. Also no calls to print or echo beforehand. Else you will get an error message like this:
Warning: Cannot modify header information - headers already sent by (output started at H:\xampp\htdocs\bla\test2.php:1) in H:\xampp\htdocs\bla\test2.php on line 2
That also means you cannot have a UTF-8 encoded document. That’s because UTF-8 text files output this BOM thing at the start of the file. Oh, and if you use include, the included files also cannot have any funky BOM stuffs.
You guessed it right. I got tripped by this problem. Because I often type Japanese, I set Notepad++ to use UTF-8 as its default encoding. @#^#&%$@*!!!
Tags: encoding, http, redirection, unicode, UTF-8










