• Increase font size
  • Default font size
  • Decrease font size

dynamic download link

Once, I had to face problem, how to generate download link dynamicly. I did not want everybody could download my files by copy pasting link into browser. Here is the solution I have created:

First we need a regular download link. This link is directed to the php script which handles whole process of downloading. Two variables are send to the php script by "GET".

<?php
//uses hash of date to ensure security
$password = "pass";
$strToHash = date('m.d.y').$password;
$hash = hash('md5', $strToHash);
echo "<a href='dl.php?filename=icon.ico&id={$hash}'>working DOWNLOAD</a><br><br>";
echo "<a href='dl.php?filename=icon.ico&id=1'>not working DOWNLOAD</a>";
?>

  1. filename which we want to download
  2. id which is our MD5 hash generated based on the date and a password.
Everythig looks like this:

As you can see, hypertext runs dl.php script. This script has two tasks:

  1. control if it was run by our link. It is done by the hash control
  2. allow us to download the requested file (defined by filename variable)
Here is the code:
<?php
$download_path = "C:\\";    //directory where downloadable files are stored
$password = "pass";         //password
$filename = $_GET['filename'];
$hash1 = $_GET['id'];
$strToHash = date('m.d.y').$password;
$hash2 = hash('md5', $strToHash);
if(strcmp($hash1, $hash2) != 0){
die("Please try again later.");
}
// Detect missing filename
if(!$filename) die("I'm sorry, you must specify a file name to download.");
// Make sure we can't download files above the current directory location.
if(eregi("\.\.", $filename)) die("I'm sorry, you may not download that file.");
$file = str_replace("..", "", $filename);
// Make sure we can't download .ht control files.
if(eregi("\.ht.+", $filename)) die("I'm sorry, you may not download that file.");
// Combine the download path and the filename to create the full path to the file.
$file = "$download_path$file";
// Test to ensure that the file exists.
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
// Extract the type of file which will be sent to the browser as a header
$type = filetype($file);
// Send file headers
header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
readfile($file);
?>

Source code, you may download here.

 

 

Comments  

 
0 #768 Harleycic 2019-07-15 11:39
Download 918Kiss – 918indo.com More info>>>: http://www.918indo.com/download-918kiss/
Quote
 
 
0 #767 Harleycic 2019-07-15 11:37
SportsBook – 918indo.com More info...: http://www.918indo.com/sportsbook/
Quote
 
 
0 #766 HarleyBaifs 2019-07-15 11:35
Daftar 918Kiss – 918indo.com Show more!..: http://www.918indo.com/daftar-918kiss/
Quote
 
 
0 #765 Harleycic 2019-07-15 07:57
Playtech Indonesia – 918indo.com Show more!..: http://www.918indo.com/playtech-indonesia/
Quote
 
 
0 #764 HarleyBaifs 2019-07-15 07:55
918Kiss SCR888 Indonesia – 918indo.com 918Kiss SCR888 Indonesia – 918indo.com...: http://www.918indo.com/918kiss-scr888/
Quote
 
 
0 #763 Harleycic 2019-07-15 05:33
SportsBook – 918indo.com Click here!: http://www.918indo.com/sportsbook/
Quote
 
 
0 #762 Harleycic 2019-07-15 05:31
Deposit 918Kiss – 918indo.com Deposit 918Kiss – 918indo.com!..: http://www.918indo.com/deposit-918kiss/
Quote
 
 
0 #761 HarleyBaifs 2019-07-15 05:29
Daftar 918Kiss – 918indo.com Click here>>>: http://www.918indo.com/daftar-918kiss/
Quote
 
 
0 #760 Harleycic 2019-07-15 03:21
918Kiss SCR888 Indonesia – 918indo.com Show more...: http://www.918indo.com/918kiss-scr888/
Quote
 
 
0 #759 Harleycic 2019-07-15 03:20
Login 918Kiss – 918indo.com Click here...: http://www.918indo.com/login-918kiss/
Quote
 
 
0 #758 HarleyBaifs 2019-07-15 03:18
Download 918Kiss – 918indo.com Download 918Kiss – 918indo.com!: http://www.918indo.com/download-918kiss/
Quote
 
 
0 #757 Harleycic 2019-07-14 09:45
Login 918Kiss – 918indo.com Show more!..: http://www.918indo.com/login-918kiss/
Quote
 
 
0 #756 Harleycic 2019-07-14 09:43
Withdraw 918Kiss – 918indo.com Click here!..: http://www.918indo.com/withdraw-918kiss/
Quote
 
 
0 #755 HarleyBaifs 2019-07-14 09:41
918indo.com – Online Casino Indonesia Show more!: http://www.918indo.com
Quote
 
 
0 #754 live casino gambling 2019-07-13 21:06
We must first obtain a copy of Ubuntu Server onto an empty CD or some regarding
portable device. Next, look for the Adobe Photoshop folder
and open the situation. When on the page, you can get three links for the cars.
Quote
 
 
0 #753 m.2 m slot 2019-07-13 14:23
It isn't fair, either to thhe other parent in order to the child to impose your conflicted emotions on him.
A spa party end up being just time you needed to relax somewhat.
Take someone oon you who could be trusted.


Also visit myy websitge m.2 m slot: http://snnadstore.net/__media__/js/netsoltrademark.php?d=918Kiss.poker%2Fdownloads
Quote
 
 
0 #752 m.2 m slot 2019-07-13 14:22
It isn't fair, either to thhe other parent in order to the child to impose your conflicted emotions on him.
A spa party end up being just time you needed to relax somewhat.
Take someone oon you who could be trusted.


Also visit myy websitge m.2 m slot: http://snnadstore.net/__media__/js/netsoltrademark.php?d=918Kiss.poker%2Fdownloads
Quote
 
 
0 #751 mega casino dk 2019-07-12 12:27
A associated with the people experience fear whesn offer to speak in front of a gaggle or audience.

The more detail the less confusion there
often be and less chance s/he will fall back into the old behaviours.


Viswit my blog - mega
casino dk: http://gobeyondinsurance.net/__media__/js/netsoltrademark.php?d=www.erafbo.com%2F__media__%2Fjs%2Fnetsoltrademark.php%3Fd%3D3win8.city%2Fother-games%2Fmega888%2F25-mega888
Quote
 
 
0 #750 live poker vienna 2019-07-12 10:55
This activity obtained attracted 290,000 gamers the actual world recreation towards the day time
period of launch. If you lose, att least you know you only lost what you are
able afford. You will get 24*7 availability throughout time.


My web page :: live poker vienna: http://banner19.com/__media__/js/netsoltrademark.php?d=Ace333.gdn%2Findex.php%2Fother-games%2Fntc33%2F11-ntc33
Quote
 
 
0 #749 live poker vienna 2019-07-12 10:55
This activity obtained attracted 290,000 gamers the actual world recreation towards the day time
period of launch. If you lose, att least you know you only lost what you are
able afford. You will get 24*7 availability throughout time.


My web page :: live poker vienna: http://banner19.com/__media__/js/netsoltrademark.php?d=Ace333.gdn%2Findex.php%2Fother-games%2Fntc33%2F11-ntc33
Quote
 
 
0 #748 d&m slot cars 2019-07-12 06:05
Submissions are all hunger suppressant .
information combined with your product on marketing is going to.
You may not realize this, but content on Myspace is picked up by search engines very,
at enoromus speed.
Quote
 
 
0 #747 l88 2019-07-12 01:47
Meaning that bulk should be used for intent. This is just a short
explanation from the you ought to cover.it should reinforce, or support, the headline.

So, what perform going to place in its pages?
Quote
 
 
0 #746 l88 2019-07-12 01:46
Meaning that bulk should be used for intent. This is just a short
explanation from the you ought to cover.it should reinforce, or support, the headline.

So, what perform going to place in its pages?
Quote
 
 
0 #745 .22 live pistol 2019-07-10 16:38
Not all pages on your website have same
page authority. Google relies on a fairly democratic system by features vast link structure decide a page's value.
Following these tips will a person to do so.
Quote
 
 
0 #744 sky777 casino 2019-07-10 11:09
I don't know whether it's just mme or if everyone else encountering problems wuth your blog.
It appears like somje of the text in your content are running off the screen. Caan someone else please comment and let me know if this is
happening to them too? This might be a issue with my web browser because
I've had thhis happen before. Kudos

Feel free to sujrf to my web site: sky777 casino: https://Kasinovin.com/home/sky-777/55-sky777
Quote
 
 
0 #743 Harleycic 2019-07-10 05:44
Daftar 918Kiss – 918indo.com More info!: http://www.918indo.com/daftar-918kiss/
Quote
 
 
0 #742 HarleyBaifs 2019-07-10 05:35
Daftar 918Kiss – 918indo.com Click here>>>: http://www.918indo.com/daftar-918kiss/
Quote
 
 
0 #741 Harleycic 2019-07-10 02:16
Withdraw 918Kiss – 918indo.com Withdraw 918Kiss – 918indo.com!: http://www.918indo.com/withdraw-918kiss/
Quote
 
 
0 #740 HarleyBaifs 2019-07-10 02:08
SportsBook – 918indo.com Show more>>>: http://www.918indo.com/sportsbook/
Quote
 
 
0 #739 HarleyBaifs 2019-07-09 23:11
Daftar 918Kiss – 918indo.com More info...: http://www.918indo.com/daftar-918kiss/
Quote
 
 
0 #738 HarleyBaifs 2019-07-09 20:32
Withdraw 918Kiss – 918indo.com More info!..: http://www.918indo.com/withdraw-918kiss/
Quote
 
 
0 #737 HarleyBaifs 2019-07-09 17:35
Download 918Kiss – 918indo.com Show more...: http://www.918indo.com/download-918kiss/
Quote
 
 
0 #736 lpe88 2019-07-09 16:44
At dances teens skulk on to a remote darkened area to kiss without
getting caught. These games are not in order to those who are dating.

You won't run regarding choices when actively playing these video
gaming.
Quote
 
 
0 #735 lpe88 2019-07-09 16:43
At dances teens skulk on to a remote darkened area to kiss without
getting caught. These games are not in order to those who are dating.

You won't run regarding choices when actively playing these video
gaming.
Quote
 
 
0 #734 HarleyBaifs 2019-07-09 14:17
Mega888 – 918indo.com More info...: http://www.918indo.com/mega888/
Quote
 
 
0 #733 HarleyBaifs 2019-07-09 10:58
Withdraw 918Kiss – 918indo.com Withdraw 918Kiss – 918indo.com...: http://www.918indo.com/withdraw-918kiss/
Quote
 
 
0 #732 pb 2019-07-09 09:10
SEO will and shouldn't ever replace offline marketing you choose to do.
Check the low numbers in local amount of searches. Search engines look for keywords which have being seached for.
Quote
 
 
0 #731 pb 2019-07-09 09:10
SEO will and shouldn't ever replace offline marketing you choose to do.
Check the low numbers in local amount of searches. Search engines look for keywords which have being seached for.
Quote
 
 
0 #730 pb 2019-07-09 09:09
SEO will and shouldn't ever replace offline marketing you choose to do.
Check the low numbers in local amount of searches. Search engines look for keywords which have being seached for.
Quote
 
 
0 #729 Harleycic 2019-07-08 05:04
Playtech Indonesia – 918indo.com Click here!..: http://www.918indo.com/playtech-indonesia/
Quote
 
 
0 #728 HarleyBaifs 2019-07-08 04:56
Playtech Indonesia – 918indo.com Click here>>>: http://www.918indo.com/playtech-indonesia/
Quote
 
 
0 #727 Harleycic 2019-07-08 02:14
918indo.com – Online Casino Indonesia Show more!: http://www.918indo.com
Quote
 
 
0 #726 HarleyBaifs 2019-07-08 02:05
Daftar 918Kiss – 918indo.com Click here!..: http://www.918indo.com/daftar-918kiss/
Quote
 
 
0 #725 Harleycic 2019-07-08 00:02
918indo.com – Online Casino Indonesia 918indo.com – Online Casino Indonesia...: http://www.918indo.com
Quote
 
 
0 #724 HarleyBaifs 2019-07-07 23:54
Download 918Kiss – 918indo.com Click here!: http://www.918indo.com/download-918kiss/
Quote
 
 
0 #723 Harleycic 2019-07-07 21:51
Download 918Kiss – 918indo.com More info>>>: http://www.918indo.com/download-918kiss/
Quote
 
 
0 #722 HarleyBaifs 2019-07-07 19:15
Rollex – 918indo.com Click here!..: http://www.918indo.com/rollex/
Quote
 
 
0 #721 Harleycic 2019-07-07 16:34
Rollex – 918indo.com Rollex – 918indo.com...: http://www.918indo.com/rollex/
Quote
 
 
0 #720 HarleyBaifs 2019-07-07 16:25
Deposit 918Kiss – 918indo.com Click here...: http://www.918indo.com/deposit-918kiss/
Quote
 
 
0 #719 HarleyBaifs 2019-07-07 13:11
Playtech Indonesia – 918indo.com Playtech Indonesia – 918indo.com!..: http://www.918indo.com/playtech-indonesia/
Quote
 
 
0 #718 HarleyBaifs 2019-07-07 10:49
Playtech Indonesia – 918indo.com More info!: http://www.918indo.com/playtech-indonesia/
Quote
 
 
0 #717 HarleyBaifs 2019-07-07 08:25
SportsBook – 918indo.com More info!: http://www.918indo.com/sportsbook/
Quote
 

Add comment

No bad words.


Security code
Refresh


New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2140 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 3034 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4554 Hits
gpsim tutorial Machine Learning and Robotics
Read More 13168 Hits

Most read content

A* search algorithm Machine Learning and Robotics
Read More 29735 Hits
PID regulator Machine Learning and Robotics
Read More 15114 Hits
gpsim tutorial Machine Learning and Robotics
Read More 13168 Hits

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2140 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 3034 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4554 Hits
gpsim tutorial Machine Learning and Robotics
Read More 13168 Hits
Design by i-cons.ch / etosha-namibia.ch