EGN
EGN

Reputation: 2572

force downloading one range only

i want to force download manager to download only one range of bytes.

what is happening now, my download manager request multiple ranges from my php file, i don't want this happen (i have reasons for that) is there any http header to set to force one range download only??

i'm using this code to block any second range connection but the problem with code, resume is disabled

if ($_SERVER['REQUEST_METHOD']=='GET' && isset($_SERVER['HTTP_RANGE']) && $range=stristr(trim($_SERVER['HTTP_RANGE']),'bytes='))
{
$arrr = explode('-', $range);
if (isset($arrr[1])) die();
$f= fopen('era','w');
fwrite($f, $range);
fclose($f);
$start_range = $arrr[0];
$range=substr($range,6);
header("Content-Range: bytes $range/$filesize");
}

Upvotes: 2

Views: 265

Answers (1)

EGN
EGN

Reputation: 2572

I actually found a trick to solve this problem, it might not be the professional way but it works like a charm. i check the header range, if its from xxxx bytes to the end then allow it. if its asking for range xxx to yyy then send a bad header(this is the trick) so that the download manager will wait for a valid respond but it will never get so the operation will time, and the request is repeated. here is the simple if command that makes the charm

$range=substr($range,6);
$arrr = explode('-', $range);
$start_range = $arrr[0];
if(!isset($arrr[1])) header("Content-Range: bytes $range/$filesize");
else header("Content-Range: bytes bytes $arrr[0]");//bad header

Upvotes: 1

Related Questions