Re: How to forward a POSTed form to another server and catch the return for further processing
| From: | John Holmes | Date: | Sun, 15 Aug 2004 04:29:30 +0000 |
| Subject: | Re: How to forward a POSTed form to another server and catch the return for further processing | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35715@lists.php.net to get a copy of this message | ||
Yanglong Zhu wrote:
How to forward a POSTed form to another server and catch the return for further processing. I think I did this before. But now I have completely forgot how that was done. The posted form data is processed on the other server, the results should be returned or captured by the first server. Obviously my brain is not working.You can use fopen() and contexts: (mostly copied from php|architect, May 2004, www.phparch.com) $data = ''; foreach($_POST as $key=>$value) { $data .= $key.'='.urlencode($value).'&'; } $opts = array( 'http' => array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n" .
'Content-Length: '.strlen($data),
'content' => $data
));
$context = stream_context_create($opts);
$fp = fopen('http://localhost/post.php', 'r', false, $context);
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com