473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1722

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.