0

I see on many download servers virtual links created to specific IP for a specific amount of time.

I want to know if this is done by PHP or .htaccess, and how?

Thanks.

sikas
  • 5,435
  • 28
  • 75
  • 120

5 Answers5

1

.htaccess is just a means to set configuration directives for some popular webservers on a per directory basis.

You need programming at some point. PHP is one option, there are many others, my preference would be Perl.

The solution basically boils down to:

  1. Generate a code in response that whatever condition you like being met
  2. Store it somewhere (e.g. a database) with the ip address, creation time and what it is associated with
  3. Look it up when a URL that uses that code is hit, then respond with a Forbidden of the associated content
  4. Have a periodic clean up script to delete old entries and keep the database small
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Dorward: Can you provide me with an example on how to do it with .htaccess? And does the script that clean up has to work on cron jobs? – sikas May 13 '11 at 15:00
  • No, I can't provide such as example. I said you would need some programming, so .htaccess is insufficient. The clean up script doesn't have to run via cron, but cron would be a very sensible way to trigger it. – Quentin May 13 '11 at 15:04
  • I`m asking about the .htaccess, how will it look? I can build up the PHP script as I don`t know Perl. I`ll be working with PHP and I know how to create database and store/retrieve data. – sikas May 14 '11 at 07:48
  • It depends what you want to do with the .htaccess. For the purpose of achieving what you have asked in this question, it doesn't need to exist. – Quentin May 14 '11 at 07:49
1

It is done usually with both .htaccess rewrite rules along with a php script.

The responses in How to create temporary urls to prevent hotlinking in php? have some useful information and example theory you should be able to use.

Community
  • 1
  • 1
Ryan Matthews
  • 1,043
  • 9
  • 28
0
header('Content-Type: application/force-download');

$file = 'yourfilename.pdf';
$fileLocation = dirname(__FILE__) . "/..anyfolder/" . $file;
header('Content-Length:' . filesize($fileLocation));
header("Content-Disposition: inline; filename=\"".$file."\"");
$filePointer = fopen($fileLocation,"rb");
fpassthru($filePointer);
T.Todua
  • 53,146
  • 19
  • 236
  • 237
0

You can dig into the codecanyon commercial script "Protected Links - Expiring Links". It creates download links expiring by time, number of downloads and IP.

http://codecanyon.net/item/protected-links-expiring-download-links/2556861

Anupam Rekha
  • 180
  • 9
0

It involve two steps:

  1. Generating the links (which is done at the php level).
  2. Routing the request based on the url.

Step 2 typically involves regular expressions and can be done at the .htaccess level or at the php level. It can also use database queries if you cache the generated urls.

For implementation details, you may want to check out MVC frameworks. All of them have a Router object of some sort, e.g.:

http://symfony.com/doc/current/book/routing.html

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154