开发者

Temporary Links

I see on many download servers virtual links c开发者_StackOverflow中文版reated to specific IP for a specific amount of time.

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

Thanks.


.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


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.


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


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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜