• 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".

//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:
$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.

Source code, you may download here.




0 #368 umraniye escort 2019-03-17 11:46
Wonderful article! We are linking to this great post on our site.
Keep up the great writing.
0 #367 scr888 download 2019-03-15 23:57
The items which have been mentioned are only the beginning.
These are the visitors who come your world-wide-web. They'll be loyal to you ought to
you treat them fairly therefore respect.
0 #366 sky777 apk 2019-03-15 14:00
The more I take into consideration it, a lettuce salad
sounds great. That precisely what a person is supposed test.
With creativity and practice, you'll soon watch your traffic growing.
0 #365 scr888 deposit rm10 2019-03-13 01:46
You never have likely discovered the countless
benefits you specific from using points. When you continue to show her respect on consequent dates
as well, she will have a good opinion about your manners.
0 #364 junk auto 2019-03-12 20:15
It's fantastic that you are getting thoughts from this piece of
writing as well as from our dialogue made here.

Visit my web-site: junk auto: https://theconversation.com/profiles/lassiter-broe-694146
0 #363 e-win scr888 2019-03-11 20:08
If you're like me, the search to be in shape, manage weight and overall well-being, at times, feels
disastrous. Who knows have got made this good difficulty?
This holds true for a lot of aspects.
0 #362 ocean king logistics 2019-03-06 10:28
She will be judging you long prior to taking any steps towards her very own. Jesus told
a parable that serves that actual suggests risks of bydureon that being irritating can be a spiritual gift.
0 #361 football betting uk 2019-03-05 00:20
Adsense is best suited for when website has a primary focus.
Offsite SEO techniques your key to scoring high in a google.
Ebooks cannot replace such history.
0 #360 online casino jobs 2019-03-04 07:39
Or rename your 'download' folder as 'download-cheap-web-templates'.
If you have found this article then tend to be obviously aware that
making cash with a blog is possible. It is easy to do right and takes little time.
0 #359 sky777 2019-03-03 22:05
This change of heart was hard acknowledge.
Yes, online trading can be highly triumphant. Can certainly usually locate a
very significant amount this way. A massage session will really relax
0 #358 ace 333 2019-02-27 19:52
This is when you end up being a very good writer. So hard work and learning are part and parcel with
the affiliate marketing business. By placing your links carefully and consistently, you
will slowly build up residual financial.
0 #357 scr888 kiss download 2019-02-27 06:00
It is probab a grain of sand that irritates an oyster and
eventually produces a pearl. It is a psychological name used to
reflect an individual's overall appraisal and evaluation in his own merit.
0 #356 scr 888 2019-02-27 04:40
Practice the body language - look to provide a man who has control but is totally self-confident.
They invade my space, waste my time, and
onboard my anxiousness. This reduces your anxiety to an exceptional extent.
0 #355 online marketing 2019-02-26 09:28
So a quality website undoubtedly help you make more resources.
Many families choose a prayer that reminds them of their loved at least one.
Do you might have any special needs that the web site addresses?
0 #354 live 222 2019-02-26 07:30
Hmm is anyone else experiencing problems with the images on this blog loading?
I'm trying to find out if its a problem on my end or if it's the blog.
Any responses would be greatly appreciated.
0 #353 lpe88 apk 2019-02-25 23:45
This applies for quite a bit of aspects. It holds true
that any kind of gathering, you can tell who the 'wide readers' are.
Why don't you are doing it this solution?
0 #352 sky777 download 2019-02-24 21:26
All of this perfect for news which will do wonders for your
SEO hard works. Maybe is usually something as
simple as a zero cost course. Many people like to have a large page.
0 #351 lucky palace casino 2019-02-23 14:39
Incredible! This blog looks just like my old one!
It's on a totally different topic but it has pretty much the same page layout and design. Superb choice of colors!
0 #350 ace333 apk 2019-02-23 00:57
One from the simplest strategies to make cash with Squidoo
is by using anchor listings. There are all kinds of free software
that you can use to get was launched. Anything worth having is never easy to accumulate.
0 #349 live 2231 2019-02-22 20:01
Why users still use to read news papers when in this technological globe all is existing on web?
0 #348 live22 apk 2019-02-22 11:53
Eg, compose and send out one post full week to a high-traffic blog in your niche.
Use the potency of social networks like Facebook, Google+, Linkedin. SEO will
and should never replace offline marketing your are performing.
0 #347 918kiss 2019-02-21 13:26
Hello every one, here every one is sharing these
kinds of know-how, thus it's fastidious to read this
blog, and I used to visit this web site everyday.
0 #346 asia gaming 2019-02-20 16:21
You must consider in order to do if for example the market does not conveniently
move your opportunity. One of my favorite
things to teach nurses is the fact , everything we do has an outcome.
0 #345 live22 download 2019-02-19 22:28
Thanks to my father who stated to me regarding this
website, this blog is genuinely amazing.
0 #344 live casino music 2019-02-19 22:18
He's a non-roster invitee, making them just about as much a longshot as 40-man roster members Cofield and Jones.
Evident than when you Quentin's second five RBI game of the year.
Grip on a securities and exchange commission's.

Add comment

No bad words.

Security code

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2066 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2933 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4151 Hits
gpsim tutorial Machine Learning and Robotics
Read More 10472 Hits

Most read content

A* search algorithm Machine Learning and Robotics
Read More 18557 Hits
PID regulator Machine Learning and Robotics
Read More 10657 Hits
gpsim tutorial Machine Learning and Robotics
Read More 10472 Hits

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2066 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2933 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4151 Hits
gpsim tutorial Machine Learning and Robotics
Read More 10472 Hits
Design by i-cons.ch / etosha-namibia.ch