• 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 #307 ntc33 login 2019-01-22 07:47
The body can range from two paragraphs to a website in length and girth.
Method it continues really caused by the heart and with you somewhat
shape or form! What this means by "content will be the king"?
0 #306 mega888 casino 2019-01-22 06:09
That way it holds really caused by the heart and through you and for some reason shape or form!
The best keywords to use are things that got 200-800 searches.

The problem most develop is enterprise.
0 #305 rollex11 2019-01-22 05:49
With havin so much content and articles do you ever run into
any problems of plagorism or copyright infringement?
My blog has a lot of exclusive content I've either written myself or outsourced but it appears a lot of it
is popping it up all over the web without my agreement.
Do you know any ways to help stop content from being stolen? I'd certainly
appreciate it.
0 #304 918k 2019-01-20 11:05
But when you move from center and follow your ki (life energy),
the endeavor is effortless. A spa party may just time you required to relax some time.
To make the gift more meaningful, generally be personalised it.
0 #303 shop design chic 2019-01-20 05:41
I visited several web pages however the audio quality for audio songs present at this
website is in fact wonderful.
0 #302 lpe88 apk 2019-01-19 23:37
This makes video marketing today a rather wise investment of
your advertising bucks each month. Switching from one advice
to before i forget- nothing but a mere waste of your time and concentration.
0 #301 ntc33 datasheet 2019-01-19 05:21
Use direct mail as well as email as follow-up methods.
You need to allow them to get learn you like a person. Traffic should also go submit hand with gaining money.
6) Your website is confusing to purposes.
0 #300 ace333 download 2019-01-18 13:17
They will become fans and come begging back for increased.
This is a very good means of getting initial
traffic on your own site. You can't just develop a post and end up forgetting about this tool.
0 #299 mega casino slots 2019-01-18 08:28
However, we are in a different world than we did 2 or 3 in the past.
It is important that you find good learning material if you want to be a proficient violinist.
Spread betting has been said to make bigger winnings.
0 #298 3star88 betting 2019-01-17 12:12
On top of that, they enroll you automatically into a generous rewards program.

Large payouts are routine in 50 Lions bonus game.
They are usually paid as well as spare. That being said; have
a budget under consideration.
0 #297 mega casino 2019-01-16 00:26
Hello Dear, are you actually visiting this
site regularly, if so afterward you will without doubt get
pleasant experience.
0 #296 ag.joker123 net 2019-01-14 09:28
We stumbled over here by a different web page and thought I might as well check things out.
I like what I see so now i am following you.
Look forward to going over your web page yet again.
0 #295 lpe88 download 2019-01-14 01:27
I every time emailed this weblog post page to all my friends,
since if like to read it then my contacts will too.
0 #294 rollex11 login 2019-01-12 17:06
There amongst the way to complete this that out ways another treatment.
Might be the way you present the product page. Now that the release is complete, we should submit it to various submission procedures.
0 #293 live 22644 2019-01-12 07:03
Thus, a lot of you would most likely go around asking
other players using this. The suspense is high the way they watch the little
white ball bounce at a distance. When I just sit back and let things work they work.
0 #292 sic bo dice pattern 2019-01-12 04:44
A well crafted first paragraph is essential.
Sites such as MySpace and Facebook can be utilized in a
number many ways. Once you do this, you'll be amazed
at how much traffic will begin to filter in order to your web site.
0 #291 Refugio 2019-01-12 03:12
However, you may make use of three images of a very similar genre.
Tackle essentials first will probably soon have your home looking lots
more beautiful. This tourist town carries with it a remarkably rich history.
0 #290 m.scr888 hack 2019-01-11 04:50
Hello, I enjoy reading all of your article post. I wanted to
write a little comment to support you.
0 #289 online casino nc 2019-01-10 23:38
excellent issues altogether, you simply won a new
reader. What could you suggest in regards to your publish that you simply made a few days ago?
Any sure?
0 #288 newtown ntc33 2019-01-10 16:48
Excellent write-up. I definitely love this site. Thanks!
0 #287 ace 333 2019-01-10 14:42
What joint ventures really are is leveraging on the efforts of
others to generate mutual wealthiness. You could write
your own content anyone could hire someone to treat it for most people.

Add comment

No bad words.

Security code

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2041 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2896 Hits
Inverse kinematics Machine Learning and Robotics
Read More 3960 Hits
gpsim tutorial Machine Learning and Robotics
Read More 9667 Hits

Most read content

A* search algorithm Machine Learning and Robotics
Read More 15907 Hits
gpsim tutorial Machine Learning and Robotics
Read More 9667 Hits
PID regulator Machine Learning and Robotics
Read More 9433 Hits

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2041 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2896 Hits
Inverse kinematics Machine Learning and Robotics
Read More 3960 Hits
gpsim tutorial Machine Learning and Robotics
Read More 9667 Hits
Design by i-cons.ch / etosha-namibia.ch