Jump to content

Recommended Posts

i need to workout a solution for massive load on my server due to downloads by restricting no. of downloads per ip (i.e restrict no of allowed downloads per ip).
i couldnt really find any tutorial directly related to this stuff if there is any please let me know i would highly appretiate that
If not, could someone kindly plot out a rough sketch to achieve this objective. What things would i need to do inorder to be able to implement this. I think though it has something to do with sessions... though i havent gone through a tutorial of sessions so i cant say much if someone could help me in this regard i would be real thankful.
I would really appretiate the effort if someone could let me know of good tutorials for the things required to achieve this objective.
Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/5093-limit-no-of-downloadsper-ip/
Share on other sites

you could work with something like:

$downloadnumber = 0;
$ip = $_SERVER['REMOTE_ADDR'];

if ($downloadnumber <= 2) {

echo "<a href=download.zip>Download</a>";

} else {

echo "You have reached the maximum number of downloads.";

}

and have it write the ip along with the number of times they have downloaded to a file? pull from the file? Then clear it everyonce in awhile...That could be a start I guess...I'm newb.
Better:

Store their IP in a database table along with the number of downloads and the date/time they downloaded the files. When a download is attempted, check the table and the number of downloads before passing them along to the actual download page. If they've surpassed their limit, send them to a different page.

I'd also have another script that runs on that page that reduces their download count after a certain period of time, or provide some way to earn points towards more downloads or something.
[qoute]
I'd also have another script that runs on that page that reduces their download count after a certain period of time, or provide some way to earn points towards more downloads or something.
[/quote]
if you could send me that would be great... i mean if its ok with you [convinceme_@hotmail.com]

Ahh i get it... but i had a lil confusion with this concept... though doesnt make sense why i have confusion but still let me ask so i can clear it :D *sorry if it sounds irritating:D*

i get it once the download starts i store the ip and time... but now how do i remove it from the database once the download is complete :O as in how do i know that the last download being done by the user has completed... i dont want to restrict no. of downloads/per ip as in allow him 1 download for one day or one week... i want to restrict simultaneous downloads

*I think thats because i wasnt clear while asking that question.. maybe i didnt mention simultaneous due to which there was some confusion (A) sorry for that*

and thanks guys for that prompt reply :)
[!--quoteo(post=355797:date=Mar 17 2006, 03:19 AM:name=convinceme)--][div class=\'quotetop\']QUOTE(convinceme @ Mar 17 2006, 03:19 AM) [snapback]355797[/snapback][/div][div class=\'quotemain\'][!--quotec--]
but now how do i remove it from the database once the download is complete :O as in how do i know that the last download being done by the user has completed... i dont want to restrict no. of downloads/per ip as in allow him 1 download for one day or one week... i want to restrict simultaneous downloads

*I think thats because i wasnt clear while asking that question.. maybe i didnt mention simultaneous due to which there was some confusion (A) sorry for that*

and thanks guys for that prompt reply :)
[/quote]

You don't... as far as I know.. What you would do is just delay the time it takes before they can start downloading again based on the time stored in the database for their last download.. don't ever remove anything from your database unless you absolutely need to... this will let you write reports, let you analyze the hotspots of your site.. statistics and data retention is important!!
I agree with keeB, but I would suggest not revealing the actual adress of the files to your end-users. To pass the file by including the file and using a header statement to tell the browser what type. That way they can't actually see where to get the files. If they can get the address of your files then they don't have to use your page and then they bypass your download limiter. It's just a thought.
ok ahmm i get that but my point is ... different people have different download speed one person takes 1 min to download same thing while the other might take an hour... now the thing is we want to limit simultaneous downloads which means he shouldnt be allowed to download unless the previous is complete.. and what you said , as in what i understood, was set a specific time after which they can download which is a hard coding rite? so could you kindly put some light on this issue :)

[b]txmedic03[/b] i highly appretiate your idea i have tried implementing that but there is a little problem with it.. i couldnt figure out how people use download.php?sid=129 for example... i had to give in the song name the folder name in order to make it work so it looked somehing like that download.php?name=putyourlightson&folder=santana ... now using header as soon as its clicked a popup window opens and file download prompts but the problem is... i am using andromeda one can figure out the directory which it is in if they use just a little of their brain.. what would you say about this? :)
Store them in a MySQL database. :-) Then you never have to reveal a path to anyone so they could download the file anytime they want. A simple database of files with your page using header for content type and returning the file by unique identifier from the database would do fine.
oh ok i get it now :) hehe thanks.. and btw can you through some light on simultaneous download thingy... as i have lot of queries about that which i have posted earlier.. and let me post them again for your convinence
*If i store that ip and data and time of the user who is downloading a certain file from my website... nd remove it after certain time.. than that would be hard coding... some people have better download speed as compared to others... so that wont work... what i want is to restrict simulatenous downloads per ip .... and this thing doesnt really make sense to me*

Thanks in advance
I would probably have some kind of a counter on each file to restrict the number of users downloading each file as well as limiting users on the number of downloads they can have per session and I would manage the sessions and everything inside the mysql database. If you need more information on this I have a thread on here where I have been showing how to manage user sessions/login with mysql. It is my personal method, but it will show you anyway.
well i went through the php.net manual on session and what i could figure out was something below
[code]ini_set('session.referer_check','.$filepathdoh.');
session_start();
if (!isset($_SESSION['count'])) {
$_SESSION['count']=0;
}
else {
$_SESSION['count']++;
}
if ($_SESSION['count'] > 0) { echo $_SESSION['count']; echo"Download Limit Reached $filepathdoh"; }
else {
echo "Download is about to begin";}[/code]
$filepathdoh is the name of the file to be downloaded
this file is forced to download using headers

so what went wrong was that if the page with the link to the popup window which forces to download the file was kept open it wont unset session even if the download was complete...unless i had closed that main window and went through the process again

Page "A" has the link to the popup window which forces download [popup window = Page "B"] .. now once when the file is downloaded it should unset the session id probabbly cost of that session.referer_check but tht doesnt happen. Even if i close Page "B" which has the above code. I have to close Page "A" inorder to have sucess.
How to solve this issue
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.