Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP header() does not work

Does somebody know why my header() does not redirect?

The last part of my script is:

  header("location: test.php");
  die('died');

It writes:

died.

:(((

It should has to redirect before it dies, but it does not.

Do you have you any idea?

like image 558
szatti1489 Avatar asked Dec 01 '22 07:12

szatti1489


1 Answers

It's probably that you're calling header() after you are outputting some text/HTML to the browser, which is a no-no. Your header() call will be ignored if even so much as a single space of output has been sent before the call.

In other words, your header() code needs to be at the start of your script, before you display anything to the user. If that still isn't working, make sure you don't have any spaces or other whitespace by mistake outside of your php tags.

like image 101
Josh1billion Avatar answered Dec 05 '22 12:12

Josh1billion