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.
.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:
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.
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
It involve two steps:
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.: