Re: Using fsockopen
| From: | Scott Fletcher | Date: | Fri, 05 Jul 2002 15:11:57 +0000 |
| Subject: | Re: Using fsockopen | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-105672@lists.php.net to get a copy of this message | ||
Here's the simple script that will do the trick! This is what I use with
Equifax before I start using cURL. You can substitute the "HOSTNAME",
"HOSTPORT" for something else.
--clip--
<?
$errno = 0;
$errstr= "";
$socket = fsockopen(HOSTNAME,HOSTPORT,&$errno,&$errstr,30);
if(!$socket || $errno) {
logAction($errno,$errstr);
echo "Could Not Connect to Equifax !!!!<br>";
return 0;
}
$senddata = $headerstr;
$senddata .= $sendstr;
$senddatalen = strlen($senddata);
fwrite($socket,sprintf("%06d",$senddatalen),6);
fwrite($socket,$senddata,$senddatalen);
list($code,$inqdata) = getResponse($socket);
if(!$code) {
logAction(-2,"Break Up\n");
echo "Error Communicating With Equifax !!!!<br>";
fclose($socket);
return 0;
}
fclose($socket);
?>
--clip--
"Richard Lynch" <rich@phpbootcamp.com> wrote in message
news:20020704233139.WAM8262.rwcrmhc52.attbi.com@[192.168.1.103]...
> >I want to issue an fsockopen command to pass a POST data set to a remote
> >server script.
>
> If you do a Google for "posttohost and 'Rasmus Lerdorf'" you'll find
> one
> already written for you... :-)
>
> >I understand the pricipals behind fsockopen, but I cannot figure out the
> >string I need to pass to POST the data - I will be emulating the output
> >from a <Form> element.
>
> You would need to read a whole lot of HTTP RFC's to be sure you have it
> correct.
>
> Fortunately, Rasmus read all of those already :-)
>
> >In addition, how do I detect a successful operation? before closing the
socket?.
>
> Yeah, the server will send back something if it worked/failed...
>
> --
> Like Music? http://l-i-e.com/artists.htm
>