Internal redirect with a php script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a script that writes a cookie on a user's machine before
returning a (large) file to download.

The current version looks like this:

setcookie('cookie', 'value', time() + 315360000, '/', '',

header("Location: ");

This works great but I would like to avoid the browser roundtrip
created by the redirect.

I know that I can use the readfile() function but since the files I am
returning are very large I do not want the php engine to be running all
that time for a single download, nor the engine to timeout.

Do you have any suggestion on how to handle this? (my web server is



Re: Internal redirect with a php script

Just leave your code as it is. The overhead of redirect over an HTTP
persistent connection is fairly small.

If all you need to do is set the cookie, you might be able to just use

Re: Internal redirect with a php script

Thanks for the suggestion.

The problem is that some download sites want a direct link to the
download file with no redirect allowed. And yes writing a cookie is
pretty much all I need (but the value written has to come from the url


Re: Internal redirect with a php script

Quoted text here. Click to load it

Try posting at an Apache group.

As for using readfile(), that should definitely be avoided in your case
because users would lose the ability to resume an interrupted download.

Re: Internal redirect with a php script

Thank you. This is a very good point.
I will try the Apache group.


Site Timeline