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

Version 1.1

Created: October 12, 2014
Last Modified: April 1, 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/12/2014 - Version 1.0 - Force download of file in secret folder created.

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.

Back to
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 0 comments.

Displaying first 50 comments.