200 OK Message when using php header function

software development

#1

Hello,

I am using the following code:

header("Location: ");

exit();

to force a redirect in php to a file depicted by . This worked fine on my old server as it just went straight to the download location without any intermediate page. However on DH servers, I get this page:

Is there anyway to change the behavior of this? Is it a case of changing the .htaccess file? Or do I have to do something extra in my PHP code? My basic aim is to hide the actual location of the file as much as possible from the user to help prevent hot linking :slight_smile:

Thanks

Jan

Jan


#2

Jan,

While researching another issue in response to a thread in this forum, I had occasion to read up a bit on enable-force-cgi-redirect. While I could well be wrong on this, it seems as though this being set (with _SERVER[“REDIRECT_STATUS”] and REDIRECT_STATUS set to 200), in conjunction with Dreamhost suEXEC php binary setup may have something to do with what you are encountering. Both Dreamhost’s PHP4 and PHP5 cgi binaries are configured this way. If this is impacting your code, it would appear that either configuring your own php.ini, tweaking .htaccess, or a combination of each of these techniques might provide a solution.

Please be gentle with me, as I am still wading (repeatedly) through the PHP documentation/notes regarding force-cgi-redirect and have now confused myself almost as much as I have educated myself. While this may not be relevant, my “sense” of what I’m reading makes me think that it might be, so I thought I would share that thought hoping that your greater understanding of the issue might either enable you to eliminate the possibility out of hand, or allow you to make better sense out of documentation than I have.

Obviously, I might be way off base here, but you might want to investigate as to whether or not this might be an issue impacting your code.

Hopefully one of the PHP wizards that hang out here can quickly post to tell me I don’t have a clue on this if that, in fact, is the case! :wink:

–rlparker


#3

hhhmmm… cheers for the response!

I have tried setting cgi.force_redirect to 0 and I am still having no luck. I am open to alternative ways of redirecting without using the php header function…

Unless there is a way to do it using .htaccess?

Thanks

Jan

Jan


#4

okie, I have hacked around it using refresh rather than location, but this is not ideal. Is there anyway I can get the same functionality back as I had when I used location?

Thanks

Jan

Jan


#5

Hmm, I’ve used the function as you are describing without problems. Here’s a sample:

$host = $_SERVER[‘HTTP_HOST’];
header(“Location: http://$host/index.php”);

It works just as it should (auto-redirect to new location with no “middle-man” page), so I’m not sure why you would be having any problems.

Check out Gordaen’s Knowledge, the blog, and the MR2 page.


#6

Are you using any special version of PHP or anything like that? Or any special settings that you know of?

Jan