note 13519 deleted from function.fsockopen by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 21:57:20 +0000 |
| Subject: | note 13519 deleted from function.fsockopen by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22255@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