1

As mentioned in PHP Manual:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP

The output of the following code redirects to the given url without any error.Couldn't find why this didn't conform to the PHP Manual lines above.

<html>
 <body>
  <div>
   some error
  </div>
 </body>
</html>
<?php 
 header('Location: http://google.com/');
?>
Rasclatt
  • 12,498
  • 3
  • 25
  • 33
Parveez Ahmed
  • 1,325
  • 4
  • 17
  • 28
  • I personally don't know why this is. I have run into this working on a *OS X Server* running Apache, but on shared hosting it throws an error and does not work, so I tend to just obey the "header-before-output" rule. – Rasclatt Apr 10 '15 at 02:16
  • Literal `` is output as well. It only occasionally works with output buffering enabled. – mario Apr 10 '15 at 02:21
  • what error message was sent from the shared hosting? @Rasclatt – Parveez Ahmed Apr 10 '15 at 15:49
  • Just the header error regarding output already being sent...yada yada. Then the page just stops displaying after that point. This one: `Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line XX` – Rasclatt Apr 10 '15 at 18:40

0 Answers0