Download codes?
January 26, 2011 2:58 PM Subscribe
Where can I find some sort of free download-code script or software for my website?
I'd like to add to my site a place where users can enter a download code they have purchased and then download a corresponding file. Each person gets a unique download code that can only be used, say, 3 times or so.
Are there any sort of pre-made systems I can install on my site, or other ways of implementing something like this? Preferably something customizable.
I thought of trying to code a simple way of doing this myself but I'm worried about security issues (people without codes just going straight to the download link, for example).
I'd like to add to my site a place where users can enter a download code they have purchased and then download a corresponding file. Each person gets a unique download code that can only be used, say, 3 times or so.
Are there any sort of pre-made systems I can install on my site, or other ways of implementing something like this? Preferably something customizable.
I thought of trying to code a simple way of doing this myself but I'm worried about security issues (people without codes just going straight to the download link, for example).
I can think of simple ways to do this, but I don't know of any pre-made solutions.
For example:
1) store the files in a location that they are not publicly accessible (i.e., outside DocumentRoot)
2) in your database that tracks downloads, you need columns for CODE, FILE, and DOWNLOAD_COUNT
3) You have a server-side script that does effectively this:
$rows = select * from downloads where CODE = $code
if (($rows has exactly one entry) and ($rows[0][DOWNLOAD_COUNT] <> {
print "Content-Length:"
print length($rows[0][FILE])
print "\r\n"
print "Content-Disposition: attachment; filename="
print $rows[0][FILE].replace(/^.*\///)
print "\r\n"
cat $rows[0][FILE]
update downloads set DOWNLOAD_COUNT = DOWNLOAD_COUNT + 1 where CODE = $code;
}
else
{
return 403;
}
Sorry, my pseudo-code is a mash mash of perl, SQL, javascript and shell, but that's really about all the logic you need to do this.>
posted by tylerkaraszewski at 3:16 PM on January 26, 2011 [1 favorite]
For example:
1) store the files in a location that they are not publicly accessible (i.e., outside DocumentRoot)
2) in your database that tracks downloads, you need columns for CODE, FILE, and DOWNLOAD_COUNT
3) You have a server-side script that does effectively this:
$rows = select * from downloads where CODE = $code
if (($rows has exactly one entry) and ($rows[0][DOWNLOAD_COUNT] <> {
print "Content-Length:"
print length($rows[0][FILE])
print "\r\n"
print "Content-Disposition: attachment; filename="
print $rows[0][FILE].replace(/^.*\///)
print "\r\n"
cat $rows[0][FILE]
update downloads set DOWNLOAD_COUNT = DOWNLOAD_COUNT + 1 where CODE = $code;
}
else
{
return 403;
}
Sorry, my pseudo-code is a mash mash of perl, SQL, javascript and shell, but that's really about all the logic you need to do this.>
posted by tylerkaraszewski at 3:16 PM on January 26, 2011 [1 favorite]
If you're ok with using a third party solution, I know someone who's used Payloadz and seems happy with it.
posted by korej at 3:34 PM on January 26, 2011
posted by korej at 3:34 PM on January 26, 2011
This thread is closed to new comments.
posted by circular at 3:06 PM on January 26, 2011