Something like so:
/* sendToHost
* ~~
* Params:
* $proxy - Proxy you want to use
* $host - Just the hostname. No http:// 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('webcache', 'www.google.com','get','/search','q=php_imlib');
* sendToHost('localhost', 'www.example.com','post','/some_script.cgi',
* 'param=First+Paramsecond=Second+param');
*/
function sendToHost($proxy, $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($proxy, 8080);
if ($method == 'GET') {
$path .= '?' . $data;
}
fputs($fp, $method http://$host/$path HTTP/1.0\r\n);
fputs($fp, Host: $host\r\n);
if ($useragent) {
fputs($fp, User-Agent: MSIE\r\n);
}
if ($method == 'POST') {
fputs($fp,Content-type: application/x-www-form-urlencoded\r\n);
fputs($fp, Content-length: . strlen($data) . \r\n);
}
fputs($fp, Connection: close\r\n\r\n);
if ($method == 'POST') {
fputs($fp, $data);
}
while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
return $buf;
}
I've not tried this code, but I think I got it right :)
Also please note that this connects to proxys on port 8080, you might need
to change that.
Oh and I changed the http/1.1 to 1.0 because I find it has less problems :)
Hope this works/helps
Andrew
- Original Message -
From: David Yee [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, July 28, 2003 3:44 AM
Subject: [PHP] POST/GET using a proxy server
Hi all- how do I modify the following function to work over a proxy
server?
Thanks for any help.
David
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php