Solved

Download one file at a time..

Posted on 2004-08-16
5
145 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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…

763 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

8 Experts available now in Live!

Get 1:1 Help Now