I present to you GetToHost, companion function to PostToHost (found
elsewhere.)
Usage: $html =
GetToHost("http ://www.example.com ?param1=string1 ¶m2=string2 ");
Returns the full request in a string, headers and all, ready for your
parsing pleasure.
This is a modification and consolidation of other examples, but hopefully
this will save some people time. Note the host header, which satisfies HTTP
1.1 server requirements.
Season to taste.
------------------------------------------------------------------
function GetToHost($link ) {
$http_response = "";
$url = parse_url($link );
$fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or
die("Socket-open failed--error: ".$err_num. " ".$err_msg) ;
fputs($fp, "GET $url[path]?$url[query] HTTP/1.0\r\n");
fputs($fp, "Host: host.org\r\n\r\ n");
fputs($fp, "Connection : Close\r\n");
while(!feof($fp )) {
$http_response .= fgets($fp, 128);
}
fclose($fp);
return $http_response;
}