I want downloads from my site to be secure without locking my customers out too. Many security solutions I’ve seen often keep the purchaser out as well. Passwords are often forgotten and either cause the customer a headache or it’s a headache for me to try to support the purchase by constantly looking for or resetting.
My solution does not keep anyone from sharing your digital download. There must be a certain amount of trust with your clients. I just want to make it a little harder for them to share the download by hiding the link to the digital download. If I change the link at least once each day, then my customer can’t just share the link. They would have to actually share their own personal copy. Hopefully, that will bring them a little more guilt than just sharing the link.
Even if it doesn’t cut down on customers sharing, it does cut down on someone just lucking up and figuring out the download link.
I want to change the folder name in my WordPress website each day and then store this name in the options table of the database. Then when it’s time to allow my customers to access the download, I just pull the folder name from the options table of the database.
WordPress has a cool feature for scheduling events wp_next_scheduled()
. According to the WordPress Codex, the action will trigger when someone visits your WordPress site, if the scheduled time has passed.
Here’s the code I use:
// add_action('wp', 'my_activation'); function my_activation() { if ( !wp_next_scheduled( 'change_folder_name' ) ) { wp_schedule_event( time(), 'daily', 'change_folder_name'); } } add_action('change_folder_name', 'do_this_daily'); function do_this_daily() { $path = getcwd().'/put-your-path-here'; $new_value = substr(md5(rand()), 0, 12); $old_value = get_option('downloads'); rename($path.$old_value,$path.$new_value); update_option( 'downloads', $new_value ); $message = 'path = '.$path.'new value = '.$new_value; } //
This will change the folder name every day assuming that someone comes to your site to trigger the name change. If they share the link, it won’t work tomorrow!