RE: [PHP] Faking a form POST
| From: | Steve Dix | Date: | Tue, 16 Apr 2002 11:25:38 +0000 |
| Subject: | RE: [PHP] Faking a form POST | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93161@lists.php.net to get a copy of this message | ||
On 16 Apr 2002 at 12:22, .ben wrote:
> hmm, i was kinda after an in-process component like the ASP components
> ASPHTTP (http://www.ServerObjects.com) and ASPTear
> (http://www.alphasieraapapa.com).
>
> cheers tho,
>
> .b
>
Try this :
You will have to encode your data in a similar manner to a get
method, only without using the ? ie
to send hello = 1, mouse=brown
&hello=1&mouse=brown
in $data_to_send
<?
function PostToHost($host, $path, $data_to_send)
{
$fp = fsockopen($host,80);
fputs($fp, "POST $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_to_send)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, $data_to_send);
while(!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
?>
Steve Dix>==============================<steve@stevedix.de
http://www.stevedix.de/
http://www.snorty.net/
http://www.mp3.com/simpletons
http://www.geocities.com/motorcity/2706