• 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 #483 casino malaysia 2019-05-20 05:06
If you don't have one, inquire if you can photograph a
neighbor's k9. Try to find natural poses and take close
up shots and also distance providers. All search engine results are completely democratic.


my blog - casino malaysia: https://jom.fun/
Quote
 
 
0 #482 scr8888 tips 2019-05-20 01:13
The most effective SEO technique is to index tthe pages of new website.
I would advise staying clear of paid directories, unless you are feeling flush of program.

And, to whom should you sumit the articles you write?


Stop by my blog; scr8888 tips: http://www.only1-poker.com/play-online-casino-games-with-excessive-ease/
Quote
 
 
0 #481 newtown ntc33 2019-05-19 12:10
Like some other project, blogs require preparation in order to be deemed as a hit.
This is because they bring extra referral traffic as well as assist the search engines to
rank you more expensive.

Feel free to visit my web-site: newtown ntc33: https://918.cafe/downloads/1800-download-ntc33
Quote
 
 
0 #480 scr 888 2019-05-19 08:39
Companies - big and small, professionals and foloks
are all inn might. Leavinng their early comment will usually result in additional traffic extremely.
This book covers the easy yet useful.

Here is my weblog scr 888: https://superslot.app/index.php/download
Quote
 
 
0 #479 2 x m.2 slots 2019-05-18 04:39
Blackjack - This game is dealt with a dealership.
It is better to practice the casino games before you start to play these
with real income. All the players need to start the game with much less amount of
bet.
Quote
 
 
0 #478 ocean king gosport 2019-05-17 19:27
The capital city possesses rich history and offers a myriad of activities to attendees.

Be courteous, though, and possess your ticket and identification ready for the security officer
to validate.bv
Quote
 
 
0 #477 3win8 slot 2019-05-17 04:22
Merely grasping the writer's idea is inadequate.
You should start the search from the places that
near to you and go far from increasing. Attractive mugs with photos
can be provided as merchandise.
Quote
 
 
0 #476 live 22356 2019-05-16 16:29
Leaving submitting to directories comment generally result additional traffic nicely.
It must be further classified as quality leads.

But what those who are just beginning?
Quote
 
 
0 #475 casino malaysia 2019-05-16 13:29
It can be written by a friend, neighbour, relative,
et cetera. Let them exactly what has happened, and expand
curious, share why it happened. What is your belief about the markets usually?
Quote
 
 
0 #474 scr888 latest update 2019-05-16 07:32
The two are currently on the "Kiss" cruise which is headed
for your Caribbean. Beginning with the opening track Hell or Hallelujah, the 12 songs come rollicking and rolling through the
speakers. So what cost Adam Lambert the American Idol title?
Quote
 
 
0 #473 scr888 latest update 2019-05-16 07:32
The two are currently on the "Kiss" cruise which is headed
for your Caribbean. Beginning with the opening track Hell or Hallelujah, the 12 songs come rollicking and rolling through the
speakers. So what cost Adam Lambert the American Idol title?
Quote
 
 
0 #472 ocean king jack up 2019-05-16 06:18
However, many anglers avoid them as soon as the weather gets cold.
One of the most popular tips on the way to fish
them is to try to perform a hop and swim type retrieve. This is
why I degree of hard tip.
Quote
 
 
0 #471 live22 free id 2019-05-15 18:23
Do you mind if I quote a couple of your articles as long as I provide credit and sources back to
your website? My blog site is in the exact same niche as yours and my visitors would genuinely benefit from a lot of the
information you provide here. Please let me know if this okay with you.
Many thanks!
Quote
 
 
0 #470 sky777 casino 2019-05-15 11:07
Good day! Do you use Twitter? I'd like to follow you if
that would be ok. I'm definitely enjoying your blog and look forward to new updates.
Quote
 
 
0 #469 lpe88 live download 2019-05-15 10:26
Fresh food can be quite easily solved using
CSS styling. Someone teaches you that back links the traffic today comes form top search engines like Google, Yahoo and MSN.
So, the first step plays the perfect here much too.
Quote
 
 
0 #468 m rollex11 2019-05-14 01:58
If a given place are going to be haunted, your seance should be adjacent -- not on -- that place.
So perhaps walking, jogging, biking or swimming tend to be
better anyone personally.
Quote
 
 
0 #467 m rollex11 2019-05-14 01:57
If a given place are going to be haunted, your seance should be adjacent -- not on -- that place.
So perhaps walking, jogging, biking or swimming tend to be
better anyone personally.
Quote
 
 
0 #466 m rollex11 2019-05-14 01:57
If a given place are going to be haunted, your seance should be adjacent -- not on -- that place.
So perhaps walking, jogging, biking or swimming tend to be
better anyone personally.
Quote
 
 
0 #465 sky casino indigo 2019-05-14 00:23
It's highly unlikely that the website owner will approve the comment if its something mundane like "Good Site".
Don't let your thoughts deter you because you think that you're not a
'good' writer.
Quote
 
 
0 #464 m ntc33 2019-05-13 17:00
The body can range from two paragraphs to a page in size.

Method it is still really from the the heart and coming
from you somewhat shape or form! What this means by "content could be the king"?
Quote
 
 
0 #463 m ntc33 2019-05-13 16:59
The body can range from two paragraphs to a page in size.

Method it is still really from the the heart and coming
from you somewhat shape or form! What this means by "content could be the king"?
Quote
 
 
0 #462 scr888 new version 2019-05-13 16:31
I like the valuable information you provide in your articles.

I'll bookmark your weblog and check again here frequently.

I'm quite certain I'll learn many new stuff right here!

Good luck for the next!
Quote
 
 
0 #461 ace333 slot 2019-05-13 16:12
This model works but need to have to to become familiar with how to obtain traffic for your website.
You for you to do more to ensure good quality traffic.
General items are harder to sell than niche items.
Quote
 
 
0 #460 web design languages 2019-05-13 08:25
Many of the true attempting to kit out a different
office. The contracts have so many loopholes it is isn't humorous.
You are able to utilize these weblogs for generating Adsense wealth.
Quote
 
 
0 #459 live roulette review 2019-05-13 04:04
What makes their topic of conversation any much better
yours or anyone else's for that matter? She will be judging you long before you take any
steps towards your ex. Only bear in your that should not sound scripted.
Quote
 
 
0 #458 joker123 download 2019-05-12 19:52
So not really try plan article submissions for each article directory
out there? The word what will feel as if they just flow from your mind and into persons
processor.
Quote
 
 
0 #457 magnum result sunday 2019-05-12 13:49
This is born in no small part to gambling online and casinos.
In order to allow it to be simple for you, it is advisable
to know where you can bet too. Why are a lot of people about the globe gambling online these days?
Quote
 
 
0 #456 sic bo trick 2019-05-12 06:28
We've been given many models of failure, regardless.
A person's self image depends on how he sees himself.
Could certainly ask people you recognize for references
to some sort of attorney.
Quote
 
 
0 #455 lpe88 download 2019-05-11 23:56
Initially ask yourself, whether you're good, reliable,
honest, friendly or hardworking person. Individuals who desire to
get them tend to visit varied online businesses. Why don't
you attempt doing it this alternative?
Quote
 
 
0 #454 jolly joker casino 2019-05-11 19:33
But still you can not resist your eyes to see the restaurant menu card design.
But learning to learn the unknown is the envelope against which all manifestation and creation pushes.

This reduces your anxiety to the best extent.
Quote
 
 
0 #453 live casino new york 2019-05-11 19:26
Naturally, an individual use your money for is perfectly up
you r. You are also add extra security with new doors and windows.
Never start a project without understanding you are
accomplishing.
Quote
 
 
0 #452 mega 888 2019-05-11 19:06
However take assistance from automated programs to send these articles instead of doing so manually.
You'll be able to religiously submit your site to all the search electric motors.
Quote
 
 
0 #451 slot/m/f8 2019-05-11 14:22
I like the valuable information you supply to your articles.
I'll bookmark your blog and test again here regularly. I am reasonably sure I will be told
lots of new stuff proper right here! Good luck for the following!
Quote
 

Add comment

No bad words.


Security code
Refresh


New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2091 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2968 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4383 Hits
gpsim tutorial Machine Learning and Robotics
Read More 11535 Hits

Most read content

A* search algorithm Machine Learning and Robotics
Read More 23271 Hits
PID regulator Machine Learning and Robotics
Read More 12667 Hits
gpsim tutorial Machine Learning and Robotics
Read More 11535 Hits

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2091 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2968 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4383 Hits
gpsim tutorial Machine Learning and Robotics
Read More 11535 Hits
Design by i-cons.ch / etosha-namibia.ch