php3-list | 199908
Date: 08/02/99
- Next message: Josh McDonald: "[PHP3] Want to help me develop?"
- Previous message: kev: "[PHP3] Downloading URL and embedding in PHP3 output"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
I am having a problem with NULL characters in the response from HTTP servers.
I am requesting the last 128 bytes of a file from the server using the
Range: bytes=-128
header.
This works flawlessly except for responses which contains NULL characters (and
they often do, because the files being requested are binary files). The
value I am returning
at the end ($id3) has all of the response up until the first null char
instead of the full 128
bytes. I think the problem is with using string-based functions here. If
anyone can help out
by converting this to something which will work with NULL characters, I'd
greatly appreciate it
-- I've tried and haven't got very far.
Here is the code I'm using to get the response:
$sock = fsockopen($server_address,$server_port);
if ($sock)
{
fputs($sock,"GET $request_path HTTP/1.1\r\n");
fputs($sock,"Host: $server_address\r\n");
fputs($sock,"User-Agent: $agent\r\n");
fputs($sock,"Accept: */*\r\n");
fputs($sock,"Range: bytes=-128\r\n");
fputs($sock,"Connection: close\r\n\r\n");
$response = fgets($sock,128);
$response = "_$response"; /* To prevent strpos() false negative. */
if (!strpos($response,"HTTP/1.1"))
return -1;
while ($buf = fgets($sock,4096))
$response = $response . $buf;
fclose($sock);
}
else
return -1;
if (!$response)
return -1;
$firstline = substr($response,0,strpos($response,"\n"));
if (!strpos($firstline,"206"))
return -1;
if(!($scl = strpos($response,"Content-Type: ")))
$scl = strpos($response,"Content-type: ");
if(!$scl)
return -1;
$ps = strpos($response,"\n",$scl);
$id3 = substr($response,$ps+3);
if (substr($id3,0,3) != "TAG")
return -1;
if (!$id3)
return -1;
return $id3;
Regards,
Adam Whitehead
CEO - Netherworld Media
E-mail: adam <email protected>
Phone: +61 (889) 279 898
FAX: +61 (889) 273 889
Mobile: +61 (411) 241 120
Musicseek (http://www.musicseek.net)
-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Josh McDonald: "[PHP3] Want to help me develop?"
- Previous message: kev: "[PHP3] Downloading URL and embedding in PHP3 output"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

