Solved

Download one file at a time..

Posted on 2004-08-16
5
147 Views
Last Modified: 2006-11-17
Hi I run a download site and i want people to download only one file at a time because huge traffic at the time makes my server slow.. aslo i want the downloads not to support download managers...
is there any script like that..

Your help will be really appriciated..
thankyou
waiting for some good replies..
0
Comment
Question by:xp17
5 Comments
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 125 total points
ID: 11817993
I would recommend using MySql and the register_shutdown function.  Assume you have a mysql table to store the current downloaders, then you use php passthrough to pipe all your files to the client.  When the script finishes, you remove the record from the MySql table.  Your in the PHP area, so I assume your not looking for .htaccess type solutions.  The table makes the IP address a primary key so if the insert fails, the script dies and the download passthrough is never reached.

1. First create the table.
create table downloaders ( ip unsigned bigint not null primary key );

2. Get the IP address as a number.  You can also use sessions to support multiple people behind a firewall...
$IP = $_SERVER['REMOTE_ADDR'];
$IP = str_replace(".", "", $IP);

3. Create a Shutdown Function
function download_done() {
    $q = "delete from downloaders where ip = $IP";
    $r = mysql_query($q);
}

4. Register the shutdown function

register_shutdown_function('download_done');

5. Add the Download wrapper
// Add the record that were downloding or DIE
$q = "insert into current_downloaders values ($IP)";
$res = mysql_query($q) or die('Sorry, only one download at a time is allowed');

// Send the file using php
$file = passthru('echo filename');

// Implied... end of script calls shutdown function


You can improve it by using sessions or something similar instead of IP addresses.  All AOL users will be sharing the same IP ranges.  The concept is the same.


0
 

Author Comment

by:xp17
ID: 11823288
Well i am very new at php..
is there a readymade script with instructions that tells you what to do..
Thankyou
0
 
LVL 1

Expert Comment

by:danutz
ID: 11835126
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question