Solved

Download one file at a time..

Posted on 2004-08-16
5
146 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now