PHP: header ("Location ... suddenly stopped working

I changed a very simple php page on my server:

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

      

and it stopped working. I get a blank page as a result (no source in it).

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

What's happening?

thanks

+2


a source to share


6 answers


<?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 that after your final closing tag, or before opening it, the backslider character appears.

+4


a source


You saved it in utf8 format. Save the file as utf8 without bom or ansi then it should work.



+1


a source


The problem can arise if you type something on this page before the heading. Or sometimes I had the same problem when I had UTF-8 encoding for a page with a header.

0


a source


I had the same issue where redirects seemed to suddenly stop working.
It ended up on a new line before a tag <?php

that I accidentally added in some obscure include file I was using.

One of the methods I have used to troubleshoot is the Networking tab in the Google Chrome developer console . I saw a new line before 200 OK

that was telling me there was something wrong with one of my files.

0


a source


I had a problem like this. I used my own PHP MVC pattern. There was actually no error, all of a sudden my redirects stopped working. I have read tons of document. But finally added ob_start();

to the index page. And it worked.

Note: Before redirecting, you must flush the buffer. Otherwise, it cannot be redirected.

0


a source


I'm not very good with php yet, but.

I added Refresh object:

header("Refresh: 0; http://www.google.com");

      

And now it works, but it would still be good to know how the first problem came about. /Spellchecking/

0


a source







All Articles