HTTP_RANGE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benyboi
Forum Commoner
Posts: 80
Joined: Sat Feb 24, 2007 5:37 am

HTTP_RANGE

Post by benyboi »

Hi,

Just a quick question, i know HTTP_RANGE is used to resume downloads, but in my download script i have this code:

Code: Select all

if(!isset($_SERVER['HTTP_RANGE'])){
What i want is to only perform a mysql query if HTTP_RANGE is empty, which it would be if you start the download in IE for example, but do download managers do the same or do they put a 0 or 1 into HTTP_RANGE?

I just want a reliable way to know if its the start of the file being downloaded or not... so that a download counter can be more accurate, and only count a download once even though a download manager will make a few connections.

Thanks
paperplate
Forum Newbie
Posts: 16
Joined: Thu Sep 04, 2008 12:15 pm

Re: HTTP_RANGE

Post by paperplate »

The value of HTTP_RANGE (e.g."Range: ") is not a binary value. It is a range of data that is requested. The actual value will be something like "bytes=0-1023"...this tells you that the browser wants bytes 0 up to and including 1023, so 1KB of data.

What you have to do is parse $_SERVER['HTTP_RANGE'] to figure out exactly which bytes the client wants. I don't know exactly how dl managers work but I would figure that the first "range" they would want if they did multiple segments includes byte 0. So maybe just keep track of people who don't send you a range or people who send you a range that includes byte 0.


Take a look at this user contributed script on php.net which seems to serve a file with resume capabilities:
http://us3.php.net/fread#84115

Here is the what the browser/dl manager requests in the 'Range' header (what HTTP_RANGE will have):
http://www.w3.org/Protocols/rfc2616/rfc ... l#sec14.35
Post Reply