Solved

Download one file at a time..

Posted on 2004-08-16
5
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 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