PHP Header Redirect problem (no, not that common problem)

PHPredirect

Firstly, this is not the headers already sent' problem.

I have an include file, that does the redirect. This works on every server I have tried it on except the production server, which runs windows.

When I run it on the production server, it only redirects the include file, not the entire page.

I have the main file, index.php:

<?php include('red.php'); ?>
<html ....
>

And I do the redirect to another page in red.php. Then the redirected page will show up at the top of the index.php page, with the rest of the index.php html file after this page.

Have the mess up some setting in php.ini?

After some more investigation, the problem is when I use a full URL rather than a relative URL. The first will only redirect the included file. (the problem I discovered above)

while the second works correctly

red2.php:

header("Location: http://example.com/newfile.php"); header("Location: newfile.php");'

Best Answer

When I run it on the production server, it only redirects the include file, not the entire page.

That's a funny thing to say because it's not really possible. Only a single blob of data is presented to the browser you can't "redirect" part of it but you can include from multiple files in order to produce a composite blob.

Perhaps, this is what you're doing. Perhaps you're doing an include instead of a redirect. Remember a redirect is done like this:

header('Location: file.php');
exit;

The exit at the end is recommended so execution doesn't continue unnecessarily.

Related Topic