Hello,
I am writing a small php program which opens a http socket with some server, sends a head request for a particular uri.
I am fetching the content-length (if available) from the server request. And then i want to send a new request with for the same uri on the same server to get the a part of the content with the Range Header.
I don't know how exactly it is possible.
Pl. advice.
Thanks in advance.
/ -- code snippet start --- /
<?
function check($url)
{
$urlArray = parse_url($url);
if (!$urlArray[port]) $urlArray[port] = "80";
if (!$urlArray[path]) $urlArray[path] = "/";
$sock = pfsockopen($urlArray[host], $urlArray[port], &$errnum, &$errstr);
if (!$sock) $return
= "Død";
else {
$dump .= "HEAD $urlArray[path] HTTP/1.1\r\n";
$dump .= "Host: $urlArray[host]\r\n";
$dump .= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* \r\n";
$dump .= "User-Agent: MassDownloader\r\n\r\n";
fputs($sock, $dump);
while($str = fgets($sock, 1024)) {
if (eregi("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $str)) $return[code] = trim(eregi_replace("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", "\\1", $str));
if (eregi("^Content-Type: ", $str)) $return[contentType] = trim(eregi_replace("^Content-Type: ", "", $str));
if (eregi("^Accept-Ranges: ", $str)) $return[acceptRanges] = trim(eregi_replace("^Accept-Ranges: ", "", $str));
if (eregi("^Content-Length: ", $str)) $return[contentLength] = trim(eregi_replace("^Content-Length: ", "", $str));
//print $str;
//$return[data].=$str;
}
$newdump="Range: 0-99/".$return[contentLength];
print "$newdump<br>";
fputs($sock,$newdump);
$s=fread($sock, 100);
print "$s<hr>";
fclose($sock);
flush();
}
//return $return;
//return $data;
}
check("http://192.168.101.62/s.htm");
?>
/* -- code snippet end --- */