View Full Version : fsockopen() and ip address(es)...

Coastal Web
09-20-2005, 06:02 AM
Hello folks, l'm working with an fsockopen() script that has been passed along to me by a friend..

It's just a basic function to POST data to a remote script..
in any event, l wasn't sure if this is possible or not..

however my question: is it possible to have the script connect to a proxy ip/port (such as you can with curl?)

function sendToHost($host,$method,$path,$data,$ref,$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.0\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");

if ($method == 'POST')
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
if ($useragent)
fputs($fp, "User-Agent: MSIE\r\n");
fputs($fp, "Referer: $ref\r\n");
fputs($fp, "Connection: close\r\n\r\n");

if ($method == 'POST')
fputs($fp, $data);

while (!feof($fp))
$buf .= fgets($fp,128);
return $buf;

Thanks for the help, and the assistance to those willing, and knowledgeable enough to help me out w/this.

Samantha Gram.