Re: Does PHP have a way to pass form data to a remote script? [message #180679 is a reply to message #180663] |
Sat, 09 March 2013 16:29 |
iarethebest
Messages: 3 Registered: March 2013
Karma:
|
Junior Member |
|
|
Strobel is correct, cURL is likely the way to go. Typically, the ideal way to go about it would be to modify the page that the form posts to (e.g. <form method="post" action="XXX"> - where XXX is what you want to pay attention to). For example, at the top of that script, you'd add something to the effect of:
<?php
// CONFIRM THAT POST DATA IS PRESENT
if (@!empty($_POST)) {
// DEFINE REMOTE URL TO POST TO
define("REMOTE_POSTURL", "http://second.site.com/scripts/example.php");
// GRAB AND FORMAT INCOMING POST DATA
foreach ($_POST as $pKey=>$pVal) { @$postData .= "$pKey=$pVal&"; }
// REMOVE TRAILING AMPERSANDS
$postData = rtrim($postData, "&");
// CREATE/INITIALIZE CURL
$ch = curl_init(REMOTE_POSTURL);
// SET VARIOUS OPTIONS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// FINALLY, EXECUTE REQUEST AND CLOSE HANDLE
curl_exec($ch);
curl_close($ch);
}
?>
On Friday, March 8, 2013 3:12:25 AM UTC-6, M. Strobel wrote:
> Am 08.03.2013 03:39, schrieb lichunshen84(at)gmail(dot)com:
>
>> On Thursday, March 7, 2013 9:10:23 PM UTC-5, Peter H. Coffin wrote:
>
>>> On Thu, 7 Mar 2013 17:29:34 -0800 (PST), lichunshen84(at)gmail(dot)com wrote:
>
>>>
>
>>>
>
>>>
>
>>>> Hi,
>
>>>
>
>>>>
>
>>>
>
>>>> I'm not a php programmer but my customer is using Word Press and
>
>>>
>
>>>> WooCommerce (I assume php is used to do the process etc.) for their
>
>>>
>
>>>> order processing). What we would like to do is to add a function to
>
>>>
>
>>>> pass the order data / form data to a remote script so that the remote
>
>>>
>
>>>> script can capture the form data as well, no need to get anything back
>
>>>
>
>>>> to the caller (the current form processor).
>
>>>
>
>>>>
>
>>>
>
>>>> Is it doable with php?
>
>>>
>
>>>
>
>>>
>
>>> Almost certainly yes. PHP support establishing network connections by
>
>>>
>
>>> many means.
>
>>>
>
>>
>
>> Could you elaborate a bit? Even better, some sample code. Thanks.
>
>>
>
> Introduction
>
>
>
> PHP supports libcurl, a library created by Daniel Stenberg, that allows you to
>
> connect and communicate to many different types of servers with many different types
>
> of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict,
>
> file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP
>
> PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based
>
> upload, proxies, cookies, and user+password authentication.
>
>
>
> These functions have been added in PHP 4.0.2.
>
>
>
> /Str.
|
|
|