Ok, let me rephrase my question. Perhaps I am not explaining it correctly.
I have a URL like http://www.awebsite.com/aprogram?fname=bob&lname=smith&id=12345
When I put this URL in the address bar in IE, it works fine. The correct data shows up. However, if I try to print the results via an fsock query, nothing shows up. It's just blank. Here is the code I am using. Maybe someone has some insight as to what I am doing wrong.
/* sendToHost
* ~~~~~~~~~~ * Params:
* $host - Just the hostname. No [url]http://[/url] or
/path/to/file.html portions
* $method - get or post, case-insensitive
* $path - The /path/to/file.html part
* $data - The query string, without initial question mark
* $useragent - If true, 'MSIE' will be sent as
the User-Agent (optional)
*
* Examples:
* sendToHost('www.google.com','get','/search','q=php_imlib');
* sendToHost('www.example.com','post','/some_script.cgi',
* 'param=First+Param&second=Second+param');
*/
function sendToHost($host,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host,80);
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($data) . "\n");
if ($useragent)
fputs($fp, "User-Agent: MSIE\n");
fputs($fp, "Connection: close\n\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
return $buf;
}
I use the something similar to the following to call the query
sendToHost('www.awebsite.com', 'POST', '/cgi-bin/aprogram', 'fname=bob&lname=smith&id=12345');
Anyone know why this doesn't work or have a better solution?