note 13519 added to function.fsockopen.php
| From: | private at jagk dot de | Date: | Wed, 20 Jun 2001 08:25:46 +0000 |
| Subject: | note 13519 added to function.fsockopen.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14479@lists.php.net to get a copy of this message | ||
If you want to use fsockopen() to retrieve a document via HTTP, and it's not the default
document of the root, or you want to get the header, try following:
// Split into components
$URLInfo = parse_url($URL);
// If 'path' is not set, use root
$DocumentPath = ($URLInfo["path"])?$URLInfo["path"]:"/";
// If there is also a 'query'
if ($URLInfo["query"])
$DocumentPath = $DocumentPath."?".$URLInfo["query"];
// Open connection
$conn = fsockopen($URLInfo["host"], 80, &$errno, $errstr, 30);
if ($conn)
{
// Get it
fputs ($conn, "GET ".$DocumentPath." HTTP/1.0\r\n\r\n");
// Read content
while (!feof($conn))
{ echo fgets($conn,128); }
// Close connection
fclose($conn);
}
Note: You will also recieve the document header. It's terminated by a CRLF line. For more
information see RFC1945 (HTTP/1.0) or RFC2068 (HTTP/1.1) on www.rfc.net
http://www.php.net/manual/en/function.fsockopen.php