GetToHost

This is a discussion on GetToHost within the PHP Language forums, part of the PHP Programming Forums category; I present to you GetToHost, companion function to PostToHost (found elsewhere.) Usage: $html = GetToHost("http://www.example.com?param1=...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-03-2003
Han
 
Posts: n/a
Default GetToHost

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;
}


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:12 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0