Re: Getting a value back from POST (not the built-in return)
| From: | Chris Shiflett | Date: | Tue, 28 Jan 2003 21:30:25 +0000 |
| Subject: | Re: Getting a value back from POST (not the built-in return) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133442@lists.php.net to get a copy of this message | ||
--- Paul <pauljwj@earthlink.net> wrote:
> Can you fill me in on the syntax here? How would you
> write the fgets statement and how would you define
> and populate the return value on the other end?
Maybe this example will help. This searches PHP's site for
curl, outputting the HTTP content to the screen. When you
are making a socket connection like this, you get the whole
HTTP response, not just the content. This example uses an
explode() to separate headers from content, which isn't
very safe (if the content contains \r\n somewhere, it
screws up), but it will probably work for you:
<base href="http://www.php.net/">
<?
$content = php_post("www.php.net", "/search.php",
"lang=en_US&pattern=curl&show=manual");
echo $content;
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);
# This only returns the content - modify if you want to
also return the headers
return $http_content;
}
?>
Chris