I made easy script for prevent direct-downloads from other pages. (PHP script)
If you have file "http://www.mysite.com/myfiles/downloads/my_file.zip" and you want give link to some forum or page etc., you can do this:
make file "download.php" and write this into file:
In first line, the number 21 presents long of the string "http://www.mysite.com"
now the link on your page "http://www.mysite.com/download.php?f=my_file.zip" downloads file "http://www.mysite.com/myfiles/downloads/my_file.zip", but in download link will be written "http://www.mysite.com/download.php?f=my_file.zip".
When you click on this link from other page, or when you directly write this link into explorer, you not start downloading, but explorer open page "www.mysite.com/mydownloads.php" where SAME link what were written on this page starts downloads this file.
If you have file "http://www.mysite.com/myfiles/downloads/my_file.zip" and you want give link to some forum or page etc., you can do this:
make file "download.php" and write this into file:
Code :
// hide source code
// hide line numbers
// hide source code
// hide line numbers
1 <?
2 if (SubStr ($_SERVER[HTTP_REFERER], 21, 0) == "http://www.mysite.com"){
3
4 $file = $_GET[f];
5 header("Content-Description: File Transfer");
6 header("Content-Type: application/force-download");
7 header("Content-Disposition: attachment; filename="myfiles/downloads/$file"");
8 readfile ($file);
9 }
10 else {
11 header ("Location: http://www.mysite.com/mydownloads.php");
12 }
13 ?> 
In first line, the number 21 presents long of the string "http://www.mysite.com"
now the link on your page "http://www.mysite.com/download.php?f=my_file.zip" downloads file "http://www.mysite.com/myfiles/downloads/my_file.zip", but in download link will be written "http://www.mysite.com/download.php?f=my_file.zip".
When you click on this link from other page, or when you directly write this link into explorer, you not start downloading, but explorer open page "www.mysite.com/mydownloads.php" where SAME link what were written on this page starts downloads this file.
Donation:If you like our free quality work, make a donation by using Paypal and tell us what you would like to see improved on our site for the next few months. |
|
No comments yet













Page Info












