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

Version 1.1

Created: October 12, 2014
Last Modified: August 25, 2017
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

Download

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:

	
	download.php?secret=secretfolder123&file=filename.ext

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

http://seabreezecomputers.com/force_download/download.php?file=download.php&key=ef30a8e19ad0dae2748a6045bc169dba363f57de

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: http://www.seabreezecomputers.com/downloadcounter/ and place dlcounter.php in the same folder on the server as this file.

History

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 www.seabreezecomputers.com
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 0 comments.

Displaying first 50 comments.