we need a plugin or code. which work for download link expire after some hour. like when anyone click on download link its generate a string and its save to db after 24 hour this download link string expire . if anyone come again on same download link its redirect to post area. please tell me how to setup on wordpress

  • "we need" is not a question :( where is your research? what have you tried? – Mark Kaplun Apr 26 '17 at 6:13

Option 1: You can achieve this using htaccess if you have single download file/path. But if you have more files available for download. Creating a temporary file for each download requests and using htaccess is not a good idea.

                   if($typeofview=="download") {
                        header('Content-type: application/pdf');
                        header('Content-Disposition: attachment; filename="' . $fakefilename . '"');
                        header('Content-Transfer-Encoding: binary');
                        header('Content-Length: ' . filesize($actualfilename));
                        header('Accept-Ranges: bytes');

add this to your .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule fakefile.php(.*)$ orignalfile.php?$1 [L,QSA]

Option 2: Creating a symlink() for each file instead is a much better idea. This will save loads of disk space and keep down the server load.

Naming the symlink after the user's session is a decent idea. A better idea is to generate a random symlink name & associate with the session, so the script can handle multiple downloads per session. You can use session_set_save_handler() (link) and register a custom read function that checks for expired sessions and removes symlinks when the session has expired.

  • thanks for reply but we need for wordpress how to use it on wordpress – How Seek Apr 27 '17 at 4:41
  • This will not be so difficult but you need to spend some time/effort on understanding the resource material on the reference site i have given above. You can choose between the option based on your requirement and can implement. – Aishan Apr 27 '17 at 4:48

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.