PHP header location-redirect doesn't work - why?

There are several reasons why a PHP header location redirect may not work:

  1. Output has already been sent to the browser: The header function must be called before any output is sent to the browser, otherwise it will not work. This includes any whitespace before the opening PHP tag, or any echo/print statements that have been executed.

  2. Headers have already been sent: If headers have already been sent by the server, the header function will not work. This can happen if there is a space or a new line after the closing PHP tag in a file that is included by the current script.

  3. The URL is not properly formatted: The URL passed to the header function must be a properly formatted URL.

Example:

<?php
header("Location: http://www.example.com/");
exit;

Here, the script will redirect the browser to "http://www.example.com/". It's important to include the exit statement after the header redirect to prevent any further processing of the script.

It is also worth to note that in some cases, the server configuration or even browser security may prevent header redirects.

If you still face any issue, please provide the detailed error message along with your code snippet, it would be helpful to debug the issue.