Force Download of file in secret folder with 24 hour expiration of link for PHP

Version 1.1

Created: October 12, 2014
Last Modified: October 18, 2019
Subscribe to Internet Tips and Tools Feed

Force Download of file in a secret folder with 24 hour expiration of link. Or whatever timelimit in hours you specify. The link could be used along with a PayPal Buy Now button that allows a user to download a file in a secret folder for only a specific length of time. The link could be emailed to the user or displayed on the thank you page after purchase. dlc_b


Downloaded 0 times.
Please make a donation to reveal the download link.

There is no need for a database to store the key for each file because the key is created based on the current date and hour in 24 hour format. The key is encrypted with SHA1 using the secret_folder and file in the encryption.

To create a link for a file to download from the secret folder, put this on the url:


Where secretfolder123/ is the folder you specify in the variables you edit in download.php. It will create a link similar to:

Edit these variables in download.php:

	$secret_folder = "secretfolder123/"; // Make this random and hard to guess. It is like a password
		// Create the secret_folder on your server and place your downloadable files in there
	$hours_to_expire = 24;  // How many hours for link to expire

To add a mysql counter for file downloads use dlcounter.php at: and place dlcounter.php in the same folder on the server as this file.


10/18/2019 - Verison 1.1c - Added isset to $_GET variables for PHP strict mode.

8/25/2017 - Version 1.1 - Changed all PHP date() functions to gmdate() to avoid 'Warning: date(): It is not safe to rely on the system's timezone settings' in newer versions of PHP.

10/12/2014 - Version 1.0 - Force download of file in secret folder created.

Back to
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 5 comments.

Displaying first 50 comments.

1. Posted By: Dale - - October 18, 2019, 4:16 am

I have been trying to get this to work but I am not understanding how to. I get file not found when I click on the expire link it made. is there any more instructions on how to set this up with paypal buttons? thank you

2. Posted By: Jeff - - October 18, 2019, 11:32 am
Hi Dale,

I can't really help you with setting it up with a paypal button. But you may want to practice just getting it to download the file first.  You may want to re-read the instructions on the page. I changed it a bit so hopefully it makes more sense. You may want to download the new download.php. First confirm your folder structure. Is it something like this:

    |---- download.php
    |---- secretfolder123
                |----- file.txt

So edit download.php to have the secret_folder like this (Note the / ):

 Then create the key like this:


3. Posted By: dale - - October 18, 2019, 12:43 pm
Hi jeff

Thanks for writing back yes I have check that many times I still can't get it to work :( i have been pulling my hair out on this! lol maybe its something on my hosting site? I don't know what else to do at this point.

4. Posted By: Jeff - - October 18, 2019, 1:16 pm
Hi Dale,

You might want to download the new version of download.php. It does some error checking to make sure that it can find the folder and that the file exists in the folder and tells you if it can't find it before creating the key.


5. Posted By: Dale - - October 18, 2019, 2:48 pm
Hi jeff

sorry I didn't read your first msgs very about the paypal button. without knowing or having info on how to do that even if I got it to work it wouldn't help me with out knowing that info :( maybe in the future you could write something up on that so people like me know how to do it with :) Thanks