473,591 Members | 2,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetToHost

Han
I present to you GetToHost, companion function to PostToHost (found
elsewhere.)

Usage: $html =
GetToHost("http ://www.example.com ?param1=string1 &param2=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;
}
Jul 17 '05 #1
0 1734

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.