Re: header() and POST

From: Date: Thu, 19 Sep 2002 03:48:17 +0000
Subject: Re: header() and POST
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-116843@lists.php.net to get a copy of this message
Here is an example of how to manually perform an HTTP POST with PHP. If you execute this code, you should see the search results of searching the PHP manual for the term "curl" (using language en_US). Curl is another option for people who need to do this sort of thing. Happy hacking. Chris <base href="http://www.php.net/"> <? function php_post($host, $path, $data) { $http_response=""; $fp=fsockopen($host, 80); fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); 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"); fputs($fp, "$data"); while(!feof($fp)) {
       $http_response.=fgets($fp, 128);
} fclose($fp); list($http_headers, $http_content)=explode("\r\n\r\n", $http_response); return $http_content; } $content=php_post("www.php.net", "/search.php", "lang=en_US&pattern=curl&show=manual"); echo $content; ?>

« previous php.general (#116843) next »