Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Restricing downloads
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Restricing downloads
Restricing downloads
31-03-2010 8:41 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hello,
Two things I'd like to be able to do regarding a downloadable file on my site:
1) Restrict the connections from each person downloading.
2) Put a limit on the number of times the file can be downloaded per day (to prevent my site being removed again).
Anyone done this or know of any resources that may help? I saw an article on the web regarding problem 1, but it used mySql and though I'd like to get into it one day, I have no experience with it at the moment. I can cope with php though.
Thanks for any advice,
Barry.
Two things I'd like to be able to do regarding a downloadable file on my site:
1) Restrict the connections from each person downloading.
2) Put a limit on the number of times the file can be downloaded per day (to prevent my site being removed again).
Anyone done this or know of any resources that may help? I saw an article on the web regarding problem 1, but it used mySql and though I'd like to get into it one day, I have no experience with it at the moment. I can cope with php though.
Thanks for any advice,
Barry.
Message 1 of 9
(1,723 Views)
8 REPLIES 8
Re: Restricing downloads
01-04-2010 10:18 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@Barry
I posted 2 years ago about restricting the connections from each person here suggesting mod_throttle and mod_bandwidth.
I had earlier come close to having my business site removed by someone downloading a less than 1MB file and using up 147MB(if I remember correctly) doing it. See the post before
I later posted here on the subject as someone else used lots.
I can, using PHP, monitor the number of downloads and limit each IP address to 6 clicks, but not the number of connections and 'part-downloads'.
I did not get anywhere with PN installating connection limiters even though it would help prevent denial of service attacks against them.
Hope this helps....
Tony
I posted 2 years ago about restricting the connections from each person here suggesting mod_throttle and mod_bandwidth.
I had earlier come close to having my business site removed by someone downloading a less than 1MB file and using up 147MB(if I remember correctly) doing it. See the post before
I later posted here on the subject as someone else used lots.
I can, using PHP, monitor the number of downloads and limit each IP address to 6 clicks, but not the number of connections and 'part-downloads'.
I did not get anywhere with PN installating connection limiters even though it would help prevent denial of service attacks against them.
Hope this helps....
Tony
Message 2 of 9
(488 Views)
Re: Restricing downloads
01-04-2010 11:29 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks Tony. Seems you didn't get any replies to your posts.
Perhaps someone reading this can help.
Barry.
Perhaps someone reading this can help.
Barry.
Message 3 of 9
(488 Views)
Re: Restricing downloads
01-04-2010 12:32 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Best of luck Barry, but it is in PN's hands.
There is no way for you to detect (or act upon) the number of connections used to download from your site.
PN will punish you for something that you can do nothing about.
Tony
There is no way for you to detect (or act upon) the number of connections used to download from your site.
PN will punish you for something that you can do nothing about.
Tony
Message 4 of 9
(488 Views)
Re: Restricing downloads
02-04-2010 4:38 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks again Tony.
Perhaps I can try restricting the number of downloads to a sensible amount per day and see how it goes.
I'm new to PHP but know 'c' which seems very similar. I created this function today; perhaps someone would be good enough to pick holes in it for me, as it's easy to miss something obvious on your own:
EDIT: updated already, saw something obvious:
Perhaps I can try restricting the number of downloads to a sensible amount per day and see how it goes.
I'm new to PHP but know 'c' which seems very similar. I created this function today; perhaps someone would be good enough to pick holes in it for me, as it's easy to miss something obvious on your own:
EDIT: updated already, saw something obvious:
function canDownload($fileName, $maxTotalDownloads, $dbFile)
{
$data;
$canDownload = false;
if(file_exists($dbFile))
{
if(is_writable($dbFile))
{
$data = unserialize(file_get_contents($dbFile));
if($data['date'] == date('Y m d'))
{
// check if max count has been reached
if($data['today'] < $maxTotalDownloads)
{
// increase the count of the specified file and the total
@$data[$fileName]++;
$data['total']++;
$data['today']++;
// allow file to be downloaded
$canDownload = true;
}
}
else
{
// new day; reset date and counter
$data['date'] = date('Y m d');
@$data[$fileName]++;
$data['total']++;
$data['today'] = 1;
$canDownload = true;
}
// write new values back to database file
file_put_contents($dbFile, serialize($data));
}
else
{
// database not writable (CHMOD 600)
echo 'database not writable <br />';
}
}
else
{
// database file doesn't exist
echo 'database file doesn\'t exist <br />';
}
return $canDownload;
}
Message 5 of 9
(488 Views)
Re: Restricing downloads
02-04-2010 8:13 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Is the intention to have a single limit for all files or an individual limit for each file? As coded the former applies. If you intended it to be the latter, the 'today' values for each file need to be stored with the filename total as a second dimension, the filename being the first dimension. Or would you want both filename and daily totals limited to minimise risk of overshooting the traffic limit?
I think the preferred way to keep this data would be in a MySQL table rather than a file.
David
I think the preferred way to keep this data would be in a MySQL table rather than a file.
David
David
Message 6 of 9
(488 Views)
Re: Restricing downloads
02-04-2010 9:04 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hello David, thanks for checking the code, much appreciated.
A single limit for all files, the other totals are just for curiosity really.
Yes, I suppose I really aught to look into that but I know absolutely nothing about it at this stage. I need to get a book on PHP and MySQL really. I'll probably get it up and running using a file for now and change it once I know more about it.
Thanks again,
Barry.
Quote Is the intention to have a single limit for all files or an individual limit for each file?
A single limit for all files, the other totals are just for curiosity really.
Quote I think the preferred way to keep this data would be in a MySQL table rather than a file.
Yes, I suppose I really aught to look into that but I know absolutely nothing about it at this stage. I need to get a book on PHP and MySQL really. I'll probably get it up and running using a file for now and change it once I know more about it.
Thanks again,
Barry.
Message 7 of 9
(488 Views)
Re: Restricing downloads
02-04-2010 11:36 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
One potential problem you might have is with the file appearing to disappear if two downloads are attempted simultaneously (the second visitor seeing a missing-file error). To avoid that the file needs locking until the write is complete. Use of the file_put_contents LOCK_EX flag introduced in PHP 5.1 should avoid that problem. (Note: I haven't tried file locking with that function.)
David
David
David
Message 8 of 9
(488 Views)
Re: Restricing downloads
03-04-2010 12:06 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thank you David, I'll go and read up about that.
Message 9 of 9
(488 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page