I'm creating a WordPress blog with some members-only page. In those members-only posts I have my own tutorial download links which i have uploaded for FREE. Problem is I want them to stop sharing the download link for the tutorials, instead of that I want to give them links which will only works once OR It will only work when it is accessed from mydomain ..
Can anyone help me? any idea would be much appriciated.
-Regards
I'm creating a WordPress blog with some members-only page. In those members-only posts I have my own tutorial download links which i have uploaded for FREE. Problem is I want them to stop sharing the download link for the tutorials, instead of that I want to give them links which will only works once OR It will only work when it is accessed from mydomain ..
Can anyone help me? any idea would be much appriciated.
-Regards
Share Improve this question edited Dec 27, 2012 at 2:47 shea 5,6524 gold badges38 silver badges62 bronze badges asked Dec 27, 2012 at 1:25 mCrazy engmCrazy eng 1211 silver badge3 bronze badges 1- I believe that the Wordpress 'Download Manager' plugin might solve your problem! – Matt Commented Dec 27, 2012 at 7:37
2 Answers
Reset to default 1This sounds like something that eCommerce plugins should be able to handle.
My naive approach to this problem can be to generate a new URL each day by embedding the date in it and then checking with the date in the URL matches the current day before sending the file.
You will need a plugin that gives you the ability to use a shortcode to rmbed the URL, and checks the validity of it before sending the file.
// files assumed to reside at wp-content/uploads/daily
// use the shortcode like that
// [daylyurl file="file name" anchor="download it"]
add_shortcode('dailyurl','my77348_dailyurl');
function my77348_dailyurl($attr,$content='',$tags) {
$url = get_option('siteurl').'?download='.$attr['file'].'&code='.md5(intval(time()/24*60*60));
return "<a href="$url">$attr['anchor']</a>";
}
// handle the download itself
add_action('init','my77348_download');
function my77348_download() {
if (isset($_GET['download'])) {
if ($_GET['code'] == md5(intval(time()/24*60*60))) { // if it match it is legit
$f = ABSPATH.'/wp-content/uploads/daily/'.$_GET['download'];
// not sure if you can set mime types here or need to do all of this before init
readfile($f); send the file itself
exit();
} else
wp_die(404); // not legit
}
}
This is not a production grade code as there are many sanity checks I omitted, and probably has a bug or more, but I think the concept should work as long as your members don't have a big incentive to try to hack it.
I have written the plugin WP DISPATCHER that creates temporary download links where you can also set the expiration time.
You can download for free from WP Plugin Repository.