Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have been trying to figure this out:

I am creating a filehosting site with PHP and I would like to know how to limit user to 10Gb of bandwidth per day, so that they can download - just like RapidShare, until their session is expired. They will be then credited back with 25Gb.

What type of cap can I use to monitor their session of downloading (including resuming) their file?

I know I have to do something with chunk data, or the total chunks completed, and then I can calculate their total chunks.

share|improve this question

migrated from stackoverflow.com Feb 24 '10 at 4:13

This question came from our site for professional and enthusiast programmers.

    
This question is too localized and would not be useful to a large amount of other people. It also lacks understanding of punctuation and formatting. –  Tyler Carter Feb 22 '10 at 4:37
    
i speak french sorry for bad english –  Saxtor Feb 22 '10 at 4:42
    
This is NOT a PHP question, it is a server question. I think you need to go learn how your server actually works before you start a file hosting service, and you should probably learn how to type while you're at it. –  animuson Feb 22 '10 at 4:42
    
thanks for the advice –  Saxtor Feb 22 '10 at 4:49
    
Exact duplicate of [Bandwidth Monitor ](serverfault.com/questions/153123/bandwidth-monitor) –  pauska Feb 8 '11 at 14:30

3 Answers 3

up vote 0 down vote accepted

You could store the users' session IDs in a database along with an amount of data they've downloaded. Each time they download a file, check that their current_usage + size_of_file < 100mb. If it is, allow the download, otherwise present them with an error. Each day reset everyone's current_usage to 0.

share|improve this answer
    
This will be a problem if they pause/resume, as it will be a brand new request, even if they only downloaded 10Mb of a 100Mb file, it will show up as 200Mb consumed –  Mark Henderson Feb 24 '10 at 4:45
    
its something like this, rapidshare.com/faq5.html i have my code here you can see it and review it for me please check to see how i improve the coding thanks. pastebin.ca/M2c6Cyj8 password ddd –  Saxtor Jun 28 '10 at 5:03

If you want to create a file hosting site which has a limit like this, I'd thing you'll need a specific PHP script to serve the files to download, like incrediman says. If you're not too new to PHP and Web Development, I encourage you to check out this article as well: http://onlamp.com/pub/a/php/2000/09/15/php_mysql.html

In the end the central idea, however, is that end users would always visit the same script (let's say you named it 'download.php') and you'd use something like a query string to dynamically choose what content is served. So to download a filelike 'lenna.jpg' they'd visit a URL similar to "www.yoursite.ex/download.php?file=lenna.jpg ".

Since in doing this, you'll have centralized the downloading in one place/script (this is called the Information Expert Pattern/Principle) you also have a central place to log how much a user has downloaded during their session (PHP has built in support for simplistic session information... see http://php.net/manual/en/features.sessions.php) and a central place to block them once they've downloaded enough.

share|improve this answer
    
Good edit Farseeker. –  John Gardeniers Feb 24 '10 at 4:51
    
its something like this, rapidshare.com/faq5.html i have my code here you can see it and review it for me please check to see how i improve the coding thanks. pastebin.ca/M2c6Cyj8 password ddd –  Saxtor Jun 28 '10 at 5:04

Also, you should know that you can use php to initiate a download, which is what you should be doing if you want to be tracking downloads. If you simply link to the file, that won't work. So use the script to initiate the download, and increment their downloaded count that way.

More info on using a script to initiate a download: http://www.ryboe.com/tutorials/php-headers-force-download

share|improve this answer
    
thank you guys i have understand how to create that its creating a counter code of how much downloads per day/user but this is the scary part, if a user was to download the file and to stop it i want to record how much bytes the user used of downloading the file, if the user resume the file i can count how much they left off and deduct it form there traffic balance, i want to understand the amount of chunks sent to the user. –  Saxtor Jun 28 '10 at 5:01
    
its something like this, rapidshare.com/faq5.html i have my code here you can see it and review it for me please check to see how i improve the coding thanks. pastebin.ca/M2c6Cyj8 password ddd –  Saxtor Jun 28 '10 at 5:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.