• 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 #644 joker123 casino 2019-06-25 10:43
Usually always wise to use white as background for content-based websites.
Once your fun profile is created, you can start sending friends' requests.
Content is beneficial to a home-based business.

Feel free to visit my web blog; joker123 casino: https://918kiss.poker/casino-games/71-joker123
Quote
 
 
0 #643 joker123 casino 2019-06-25 10:43
Usually always wise to use white as background for content-based websites.
Once your fun profile is created, you can start sending friends' requests.
Content is beneficial to a home-based business.

Feel free to visit my web blog; joker123 casino: https://918kiss.poker/casino-games/71-joker123
Quote
 
 
0 #642 ntc33 2019-06-25 02:57
Need to state dynamics of opportunities report that you are offering.
Don't waste period writing about topics that can't help you drive your list to will probably.


my blog post - ntc33: https://918kiss.bid/downloads/219-download-ntc33
Quote
 
 
0 #641 ace333 apk 2019-06-24 21:04
Youu ssimply look at all the news papers every day and it's
clear notice how important images 're. Test out your own reactions to use first spot.


My homepage; ace333 apk: http://myslot.live/download/24-ace333
Quote
 
 
0 #640 ace333 apk 2019-06-24 21:04
Youu ssimply look at all the news papers every day and it's
clear notice how important images 're. Test out your own reactions to use first spot.


My homepage; ace333 apk: http://myslot.live/download/24-ace333
Quote
 
 
0 #639 ace333 apk 2019-06-24 21:03
Youu ssimply look at all the news papers every day and it's
clear notice how important images 're. Test out your own reactions to use first spot.


My homepage; ace333 apk: http://myslot.live/download/24-ace333
Quote
 
 
0 #638 918kiss scr 2019-06-24 11:23
Moom is treated together with a different version of behavior so that she won't be unhappy, probably.
A late sleep possibly be just as welcomed every
single other treatment. She succeeded because of her doggedness.
Quote
 
 
0 #637 918kiss scr 2019-06-24 11:22
Moom is treated together with a different version of behavior so that she won't be unhappy, probably.
A late sleep possibly be just as welcomed every
single other treatment. She succeeded because of her doggedness.
Quote
 
 
0 #636 play8oy test id 2019-06-24 06:50
Manifesting and self-empowerment accomplish not have to take years.
Congratulations to those of you who take an educational approach with your marketing making
articles. Make sure your house is generally clean and tidy.


my web page play8oy test id: http://warrentboe.net/__media__/js/netsoltrademark.php?d=kasino.games%2Fdownloads%2F316-download-play8oy
Quote
 
 
0 #635 play8oy test id 2019-06-24 06:50
Manifesting and self-empowerment accomplish not have to take years.
Congratulations to those of you who take an educational approach with your marketing making
articles. Make sure your house is generally clean and tidy.


my web page play8oy test id: http://warrentboe.net/__media__/js/netsoltrademark.php?d=kasino.games%2Fdownloads%2F316-download-play8oy
Quote
 
 
0 #634 lpe88 apk 2019-06-24 03:45
This site was... how do I say it? Relevant!!
Finally I have found something which helped me.
Thanks a lot!

My weblog - lpe88 apk: https://kasinovin.com/downloads/70-download-lpe88
Quote
 
 
0 #633 lpe88 apk 2019-06-24 03:45
This site was... how do I say it? Relevant!!
Finally I have found something which helped me.
Thanks a lot!

My weblog - lpe88 apk: https://kasinovin.com/downloads/70-download-lpe88
Quote
 
 
0 #632 lpe88 apk 2019-06-24 03:44
This site was... how do I say it? Relevant!!
Finally I have found something which helped me.
Thanks a lot!

My weblog - lpe88 apk: https://kasinovin.com/downloads/70-download-lpe88
Quote
 
 
0 #631 lpe88 download 2019-06-23 20:36
I was recommended this website by my cousin. I am not sure whether this post is written by him as
nobody else know such detailed about my difficulty. You're wonderful!
Thanks!

my website; lpe88 download: http://news.Ezyget.com/880-lpe88/profile
Quote
 
 
0 #630 lpe88 download 2019-06-23 20:35
I was recommended this website by my cousin. I am not sure whether this post is written by him as
nobody else know such detailed about my difficulty. You're wonderful!
Thanks!

my website; lpe88 download: http://news.Ezyget.com/880-lpe88/profile
Quote
 
 
0 #629 lpe88 download 2019-06-23 20:35
I was recommended this website by my cousin. I am not sure whether this post is written by him as
nobody else know such detailed about my difficulty. You're wonderful!
Thanks!

my website; lpe88 download: http://news.Ezyget.com/880-lpe88/profile
Quote
 
 
0 #628 sport casino 2019-06-23 20:27
Learn all you can do about techniques here and every one you can about increasing visitor count.
A person are can't write well yourself, get someone do it for you might.
There is a good content of potassium.

Also visit my page :: sport casino: http://uralprofil.ru/bitrix/rk.php?goto=http%3A%2F%2Facademia-moscow.ru%2Fbitrix%2Fredirect.php%3Fevent1%3D%26event2%3D%26event3%3D%26goto%3Dhttp%3A%2F%2Fwww.ezyget.com%2Fslots.html
Quote
 
 
0 #627 sport casino 2019-06-23 20:27
Learn all you can do about techniques here and every one you can about increasing visitor count.
A person are can't write well yourself, get someone do it for you might.
There is a good content of potassium.

Also visit my page :: sport casino: http://uralprofil.ru/bitrix/rk.php?goto=http%3A%2F%2Facademia-moscow.ru%2Fbitrix%2Fredirect.php%3Fevent1%3D%26event2%3D%26event3%3D%26goto%3Dhttp%3A%2F%2Fwww.ezyget.com%2Fslots.html
Quote
 
 
0 #626 m&ms slot 2019-06-23 18:29
I'm not sure why but this web site is loading extremely slow for me.
Is anyone else having this problem or is it a issue on my end?
I'll check back later on and see if the problem still exists.
Quote
 
 
0 #625 m&ms slot 2019-06-23 18:29
I'm not sure why but this web site is loading extremely slow for me.
Is anyone else having this problem or is it a issue on my end?
I'll check back later on and see if the problem still exists.
Quote
 
 
0 #624 m&ms slot 2019-06-23 18:28
I'm not sure why but this web site is loading extremely slow for me.
Is anyone else having this problem or is it a issue on my end?
I'll check back later on and see if the problem still exists.
Quote
 
 
0 #623 mega casino support 2019-06-23 16:46
This piece of writing gives clear idea in support of the new users of blogging,
that truly how to do blogging.
Quote
 
 
0 #622 mega casino support 2019-06-23 16:46
This piece of writing gives clear idea in support of the new users of blogging,
that truly how to do blogging.
Quote
 
 
0 #621 ntc33 download 2019-06-23 14:28
It's possible to gemerate more attention online you can maintain your
articles smaller. If a website is on web since a long time then it gets important.
First, analyze the website your link will be
plaed on.

Feel free to visit my blog - ntc33 download: http://3Win8.city/other-games/ntc33/19-ntc33
Quote
 
 
0 #620 ntc33 download 2019-06-23 14:28
It's possible to gemerate more attention online you can maintain your
articles smaller. If a website is on web since a long time then it gets important.
First, analyze the website your link will be
plaed on.

Feel free to visit my blog - ntc33 download: http://3Win8.city/other-games/ntc33/19-ntc33
Quote
 
 
0 #619 scr888 jammer apk 2019-06-23 05:56
You save yourself the trouble of planning to provide directions or concept.
And also, according to him, there's no mountain exorbitant
to climb. You want them to efficiently buy point across.


Takke a look at my ite :: scr888 jammer apk: http://dabird.us/__media__/js/netsoltrademark.php?d=virtualonline114casino.com%2Fwinning-at-online-poker%2F
Quote
 
 
0 #618 scr888 jammer apk 2019-06-23 05:56
You save yourself the trouble of planning to provide directions or concept.
And also, according to him, there's no mountain exorbitant
to climb. You want them to efficiently buy point across.


Takke a look at my ite :: scr888 jammer apk: http://dabird.us/__media__/js/netsoltrademark.php?d=virtualonline114casino.com%2Fwinning-at-online-poker%2F
Quote
 
 
0 #617 scr 888 ios 2019-06-23 04:05
You must consider for you to do if ypur market doesn't convdniently moe your concept.
After you have decided few attorneys, you can ibterview alll
of them to see what you think.
Quote
 
 
0 #616 scr 888 ios 2019-06-23 04:05
You must consider for you to do if ypur market doesn't convdniently moe your concept.
After you have decided few attorneys, you can ibterview alll
of them to see what you think.
Quote
 
 
0 #615 a z online casinos 2019-06-23 00:27
Additional medications things easier, you have to limit may find different fonts you use.
If you're in this position, you was at the mercy of yahoo.
Quote
 
 
0 #614 a z online casinos 2019-06-23 00:27
Additional medications things easier, you have to limit may find different fonts you use.
If you're in this position, you was at the mercy of yahoo.
Quote
 
 
0 #613 3win8 new apk 2019-06-22 07:51
Notice the cake decorating kits and matching accessories
to embellish your party cake. First, an individual
to remind yourself that barefoot running is already in you.


Feel free to surf to my weblog ... 3win8 new apk: http://g.com/?a%5B%5D=%3Ca+href%3Dhttp%3A%2F%2Fprosalescareer.com%2F__media__%2Fjs%2Fnetsoltrademark.php%3Fd%3Dkasino.games%252Fhome%252F3win81%252F54-3win8-mobile-slot%3E3win8+latest+version+download%3C%2Fa%3E
Quote
 
 
0 #612 3win8 new apk 2019-06-22 07:51
Notice the cake decorating kits and matching accessories
to embellish your party cake. First, an individual
to remind yourself that barefoot running is already in you.


Feel free to surf to my weblog ... 3win8 new apk: http://g.com/?a%5B%5D=%3Ca+href%3Dhttp%3A%2F%2Fprosalescareer.com%2F__media__%2Fjs%2Fnetsoltrademark.php%3Fd%3Dkasino.games%252Fhome%252F3win81%252F54-3win8-mobile-slot%3E3win8+latest+version+download%3C%2Fa%3E
Quote
 
 
0 #611 3win8 slot 2019-06-21 21:40
Definitely believe that which you stated. Yoour favorite reaon appeared
to be on thee internet the simplest thing to be aware of.
I say to you, I certainly get annoyed while people
think about worries that they plainly don't know about. You manahed
to hit the nail upon the top and also defined out thee whole thing without having side-effects ,
people can take a signal. Will probably be back tto get more.
Thanks

My web pge 3win8 slot: https://918.network/casino-games/70-3win8
Quote
 
 
0 #610 download 2019-06-21 13:50
Right now it looks like Movable Type is the preferred blogging platform out there right
now. (from what I've read) Is that what you're using on your blog?


Here is my blog ... download: https://www.f6s.com/hppsc1210driverswindows7
Quote
 
 
0 #609 download 2019-06-21 13:50
Right now it looks like Movable Type is the preferred blogging platform out there right
now. (from what I've read) Is that what you're using on your blog?


Here is my blog ... download: https://www.f6s.com/hppsc1210driverswindows7
Quote
 
 
0 #608 download 2019-06-21 13:50
Right now it looks like Movable Type is the preferred blogging platform out there right
now. (from what I've read) Is that what you're using on your blog?


Here is my blog ... download: https://www.f6s.com/hppsc1210driverswindows7
Quote
 
 
0 #607 download 2019-06-21 13:49
Right now it looks like Movable Type is the preferred blogging platform out there right
now. (from what I've read) Is that what you're using on your blog?


Here is my blog ... download: https://www.f6s.com/hppsc1210driverswindows7
Quote
 
 
0 #606 maca peruana 2019-06-21 13:46
I know this if off topic but I'm looking into starting my own weblog and was wondering what all is required to
get set up? I'm assuming having a blog like yours would cost a pretty penny?
I'm not very internet smart so I'm not 100% positive. Any tips or
advice would be greatly appreciated. Many thanks
Quote
 
 
0 #605 ace333 apk download 2019-06-21 02:19
Always remember the tips we've discussed here are still very much relevant aand that they matter.
Many people suggest not doing this because could annoying.
You can use trivia questions if in comparison.

My page - ace333 apk download: http://myslot.live/download/24-ace333
Quote
 
 
0 #604 ace333 apk download 2019-06-21 02:18
Always remember the tips we've discussed here are still very much relevant aand that they matter.
Many people suggest not doing this because could annoying.
You can use trivia questions if in comparison.

My page - ace333 apk download: http://myslot.live/download/24-ace333
Quote
 
 
0 #603 live22 apk 2019-06-20 17:21
This model works but wish to to be informed on how generate traffic to the website.

Joint ventures are are the ones form of leverage on the.
Advertise on identified websites and appearance engines.


Have a look at my web blog ... live22 apk: https://918kiss.poker/downloads
Quote
 
 
0 #602 3win8 slot 2019-06-20 15:54
Most people have to be able to cell phones and the world wide web.
As frequently say, it's not always understanding to write, but the
right way to write it. The problem most develop is business enterprise.


Feel free to surf to my web blog ... 3win8 slot: https://918.cafe/home/3win81/54-3win8-mobile-slot
Quote
 

Add comment

No bad words.


Security code
Refresh


New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2122 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 3012 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4492 Hits
gpsim tutorial Machine Learning and Robotics
Read More 12641 Hits

Most read content

A* search algorithm Machine Learning and Robotics
Read More 27545 Hits
PID regulator Machine Learning and Robotics
Read More 14351 Hits
gpsim tutorial Machine Learning and Robotics
Read More 12641 Hits

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2122 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 3012 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4492 Hits
gpsim tutorial Machine Learning and Robotics
Read More 12641 Hits
Design by i-cons.ch / etosha-namibia.ch