Download button that redirects to another page

Hello Everyone,

I’m looking forward to create a download button that allows users to download .exe(setup) file from my website and after that and it redirects them to another page. For example, check out the download button of this site:

freeopener*com

Is there any way to do it on a HTML website?

Hi there,

The site you link to first redirects you to the “after” page (with a “Click here if your download doesn’t start” notice) , then it initiates the download.
As far as I know, this is really the only way to do what you ask (reliably).

Linking to the after page is simple:

<a href="download.html">Click here to download your file</a>

Starting the download can then be done using a meta refresh, which is supported in most browsers:

<meta http-equiv="refresh" content="5;url=path_to_your_file/file.exe"/>

HTH

Hello,

Thank you for your reply!

There are links to different (.exe) setup files on my download page:

iphone-to-pc . com/ download . html

So I’m bit confused about where do I need to put this Meta Refresh Tag that downloads the appropriate setup file?

Hi,

If you are dealing with multiple downloads, you will ideally need to write your “Success” page in PHP or some such similar language.

All of the links on your download page would point to this “Success” page and would pass in the file they want to download as a parameter.

Your links on the download page would look like this:

<a href="success.php?file_name=file_1.exe">Click here to download file 1</a>
<a href="success.php?file_name=file_2.exe">Click here to download file 2</a>
<a href="success.php?file_name=file_3.exe">Click here to download file 3</a>

Your success page would look like this:

<?php
if(isset($_GET['file_name'])){
  $download_path = '/downloads/' . $_GET['file_name'];
} else {
  die("Please don't load this page directly!");
}
?>

<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="refresh" content="5;url=<?php echo $download_path ?>"/>
    <title>Success!</title>
  </head>

  <body>
    <h1>Your download will begin shortly!</h1>
    <p>If it doesn't begin, <a href="<?php echo $download_path ?>">click here</a></p>
  </body>
</html>

This is a simple example to demonstrate the concept.

In real life you will want to be very restrictive as to what you accept in this $_GET['file_name'], as you don’t want people downloading random files off of your server.
In your case, you only seem to be offering eight files as downloads, so you could even check for each of these individually.

<?php
  if(isset($_GET['file_name'])){
    if (preg_match('/file_\\d.exe/', $_GET['file_name'])){
      $download_path = '/downloads/' . $_GET['file_name'];
    } else {
      die("Invalid filename!");
    }
  } else {
    die("Please don't load this page directly!");
  }
?>

Hope that helps.

Hello

Sorry for the late reply. I got the concept. Thanks Dave :slight_smile:

You can search on the Internet for “Dynamic Drive” - a lot of codes and tutorials…

Can I get the free beer too?

Verry funny…

You’ll probably be reasonably safe with the example given by Pullo, but something to keep in mind when coding this sort of downloader functionality with more general paths is the dreaded Directory Traversal Attack - this is where an attacker passes in a bunch of ‘…/…/…/’ that gives them free license to download any path your server has access to.