Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Download one file at a time..

Posted on 2004-08-16
5
Medium Priority
?
150 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

715 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