Jump to content

Multiple Download From Same IP


techcone

Recommended Posts

Hello developers,

 

I want to have a simple solution for a simple file download script.

 

I want to prevent parallel download of files from same IP .

 

Like rapidshare do for free user, it allows downloading of only 1 file per IP.

 

How can I do that ?

 

Just suggest me logic and it will be fine for me :)

Link to comment
Share on other sites

write a wrapper script for downloading files...let's call it download.php...and have all downloaded files go through there (this is a pretty common thing, let me know if that part is confusing)

 

then, in your download script, before you give them the file, open a read handle on their IP address in some temp folder:

$lck = fopen($_SERVER['REMOTE_ADDR'],'r+');

then, open an exclusive lock on that file:

flock($lck, LOCK_EX);

next, serve up the file

finally, close the file handle to free up the lock

fclose($lck);

with the exclusive lock, any subsequent requests from the same IP (aka trying to lock the same file) will wait for the first request to finish. obviously, the person could still spoof their IP though

Link to comment
Share on other sites

Great job mate, so its just like mutual exclusion.

 

One small problem, I close file after downloading is complete oke ?

 

Suppose some user stops the download ?

 

Will lock be automatically removed ?

 

Or do I have to run a cron job every x minutes to remove such files ?

 

 

Link to comment
Share on other sites

Great job mate, so its just like mutual exclusion.

 

One small problem, I close file after downloading is complete oke ?

 

Suppose some user stops the download ?

 

Will lock be automatically removed ?

 

Or do I have to run a cron job every x minutes to remove such files ?

 

You should take a look in the manual for that function.

Link to comment
Share on other sites

the lock is released as soon as the script ends...even if the user cancels the download

 

...one other note...you will end up with a folder FULL of lock files (one for every IP that has ever downloaded). you may want to write a script that goes through and cleans up those files (although, they are empty...so they won't take up much space at all)

Link to comment
Share on other sites

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.