I think you misunderstand what the HTTP header Location
does.
The Location
header instructs the client to navigate to another page. You cannot send more the one Location
header per page.
Also, PHP sends headers right before the first output. Once you output, you cannot specify any more headers (unless you are using Output Buffering).
If you specify the same header twice, by default, header()
will replace the previous value with the latest one... For example:
<?php
header('Location: a.php');
header('Location: b.php');
header('Location: c.php');
will redirect the user to c.php
, never once passing by a.php
or b.php
. You can override this behavior by passing a false
value to the second parameter (called $replace
):
<?php
header('X-Powered-By: MyFrameWork', false);
header('X-Powered-By: MyFrameWork Plugin', false);
The Location
header can only be specified once. Sending multiple Location
header will not redirect the users to the pages... It will probably confuse the crap out of the UA. Also, understand that the code continues to execute after sending a Location
header. So follow that call to header()
with an exit
. Here is a proper redirect function:
function redirect($page) {
header('Location: ' . $page);
exit;
}