Jump to content


Photo

Limit No. Of Downloads/per ip


  • Please log in to reply
11 replies to this topic

#1 convinceme

convinceme
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 16 March 2006 - 05:21 PM

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.

#2 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 16 March 2006 - 06:12 PM

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.

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 16 March 2006 - 06:29 PM

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.

Info: PHP Manual


#4 convinceme

convinceme
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 17 March 2006 - 03:19 AM

[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 :)

#5 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 17 March 2006 - 03:33 AM

[!--quoteo(post=355797:date=Mar 17 2006, 03:19 AM:name=convinceme)--][div class=\'quotetop\']QUOTE(convinceme @ Mar 17 2006, 03:19 AM) View Post[/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!!

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#6 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 17 March 2006 - 05:44 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#7 convinceme

convinceme
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 17 March 2006 - 09:15 AM

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 :)

txmedic03 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? :)


#8 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 18 March 2006 - 09:34 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#9 convinceme

convinceme
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 18 March 2006 - 11:46 AM

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

#10 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 18 March 2006 - 12:02 PM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#11 convinceme

convinceme
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 18 March 2006 - 02:49 PM

i would highly appretiate if u could pm me that thingy of urs if u can post it here :)

#12 convinceme

convinceme
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 19 March 2006 - 06:52 AM

well i went through the php.net manual on session and what i could figure out was something below
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";}
$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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users