0

I have used this same code PHP redirect on a hosting site and it works fine. When I use it in Visual Studio Code with my localhost setup, it doesn't work. In PHP version 8.0 I do a

$reroutePath = "Location: http://" . $_SERVER['HTTP_HOST'] . "/test.php";
header($reroutePath);

The path is: http://localhost/test.php I have tried everything including the use of ob_start(), ob_flush(), ob_clean() before doing the header($reroutePath) and still get no reroute.

When I use the step debug in Visual Studio Code, everything works correctly but nothing occurs when it executes the header($reroutePath) code line.

Is there something I need to change or put in the php.ini-development file. I am using PHP version 8.0 in Visual Studio Code on Windows 10. This is the only problem I have ever had with my localhost PHP setup. I have the output_buffering = 4096 uncommented in my php.ini-development file. I would appreciate any help or advice.

ORHAN ERDAY
  • 1,020
  • 8
  • 31
Miff
  • 15
  • 7
  • Do you have an `exit;` after `header($reroutePath);`? If that still doesn't help, `var_dump($_SERVER)` might tell you that `'HTTP_HOST'` is empty. – Guido Faecke Jun 02 '22 at 13:58
  • Yes, I have exit after header and the HTTP_POST shows localhost:1000. I have tried everything and it executes the header($reroutePath) and the correct path is in the variable. It just executes the header line of code and moves to the exit() code line and code ends. The header just doesnt do anything. I have tried everything. I have output_buffering = 4096 in the php.ini file. I am just wondering if there is something else I need to change in my php.ini file. I can't find anymore info online of why this is not doing the reroute. – Miff Jun 02 '22 at 18:59
  • 1
    Also, make sure there is no other output happening before you reach `header()`. Look for any `echo/print` as well as any spaces or tabs outside of ` – Guido Faecke Jun 02 '22 at 20:38
  • Thanks for your help. I double checked and I had a print to show output for testing that was an empty value. – Miff Jun 05 '22 at 11:14

0 Answers0