bigboard has asked for the wisdom of the Perl Monks concerning the following question:

I have a link on a web page that a user can click to download an executeable. This is fine, but I need to redirect to a 'Thank you' page once the user has clicked the link as well as starting the download. Can anyone help?

Replies are listed 'Best First'.
Re: http redirection and download
by Chady (Priest) on Sep 24, 2001 at 16:07 UTC

    This can probably help:

    print the html output with the thank you note, and have a META refresh header tag that redirects to download the executable.

    Update: fixed typo


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
Re: http redirection and download
by hatter (Pilgrim) on Sep 24, 2001 at 16:07 UTC
    A simple way (which iirc is what tucows do) is to send them straight to a thank you page, but include a javascript open in it, that opens the file they're trying to download, so they get the prompt to open/save the file, and are then still left on the thanks page.

    Ah, seeing chadys post, using a meta refresh tag is a much better idea that javascript, though the result is the same. Also, you can actually print a real HTTP refresh/location header, instead of the meta tags (which will hide how you're doing it, to the casual user)

    the hatter

Re: http redirection and download
by bigboard (Initiate) on Sep 24, 2001 at 17:39 UTC
    Thank you both very much for your help, I've used the HTML 'refresh' method, and it works a treat:
    my $url="executeable.exe"; print "<meta http-equiv=\"Refresh\" Content=\"0;URL=$url\">\n\n";

      For a `real' header:

      print <<HTTP; Content-Type: text/html Refresh: 0;URL=http://www.MySite.DOM/myfile.tar.bz2 <html> <head><title> tnx </title></head> <body><h1> thank you </h1></body> </html> HTTP

      To save some CPU cycles, you can make that into an "unparsed" file (on my Apache box, by putting a .http extension on it) with the HTTP headers and the HTML together. The user sees only an HTML page, but there's this magic when they load it from your server that gives them the file.