[英]PHP cURL Post to and display of External Page
I am trying to rebuild a site that currently presents a form to the user, has the user click a button to post to a page that does some calcs based on the data entered, and has them hit another button to post to a payment vendor that presents a secure payment form utilizing the non-sensitive data entered. 我正在尝试重建一个当前向用户提供表单的网站,让用户单击一个按钮发布到基于输入数据进行一些计算的页面,然后让他们点击另一个按钮发布到付款供应商,使用输入的非敏感数据出示安全的付款表格。
I am trying to do the following. 我正在尝试执行以下操作。 I have written a page that presents the form for customer data entry, they click a submit button, that posts to a php file on my site, I make the calculations needed, and then post to the site using Curl.
我写了一个页面,展示了用于输入客户数据的表单,他们单击了一个提交按钮,将其发布到我网站上的php文件中,进行所需的计算,然后使用Curl发布到该网站。
I have only used cURL in the past to post to a site, check for a good process status, and continue on. 过去,我仅使用cURL发布到网站,检查状态良好,然后继续。 Can I use Curl to post to and then go to the other page in the browser, just like I do when I submit the form directly to it?
是否可以像在我直接向表单提交表单时那样,使用Curl在浏览器中发布并转到其他页面?
In Summary: 综上所述:
Can I post to a form in Curl and have it act just as if I posted from HTML form with the action set to the external site url. 我可以将其发布到Curl中的表单,并且使其具有与我将HTML表单中的操作设置为外部网站url时所发布的表单一样的作用。
If so, what I have I missed? 如果是这样,我想念的是什么?
Here is the code from the cUrl call in the php file: 这是来自php文件中cUrl调用的代码:
$fields = array(
'x_invoice_num' => urlencode($x_invoice_num),
'x_phone' => urlencode($x_phone),
'x_email' => urlencode($x_email),
'x_ship_to_address' => urlencode($x_ship_to_address),
'x_first_name' => urlencode($x_first_name),
'x_last_name' => urlencode($x_last_name),
'x_address' => urlencode($x_address),
'x_city' => urlencode($x_city),
'x_state' => urlencode($x_state),
'x_zip' => urlencode($x_zip),
'x_amount' => urlencode($x_amount),
'x_fp_hash' => urlencode($x_fp_hash),
'x_fp_sequence' => urlencode($x_fp_sequence),
'x_fp_timestamp' => urlencode($x_fp_timestamp),
'x_login' => urlencode($x_login),
'x_show_form' => urlencode($x_show_form),
'x_description' => urlencode($x_description)
);
//url-ify the data for the POST
$fields_string="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//set the url, number of POST vars, POST data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postURL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$headers = array();
$headers[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$headers[] = "Accept-Language: en-us,en;q=0.5";
$headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//execute post
//curl_exec($ch);
$curl_result = curl_exec($ch);
$OK = strpos($curl_result, 'OK');
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
The idea of having the user redirected to the secure payment provider is that he/she will enter some sensitive payment info (CC, expiry, ...) to be processed. 将用户重定向到安全支付提供商的想法是,他/她将输入一些敏感的支付信息(抄送,到期等)以进行处理。 I don't think that you have this info, among your "$fields" array, to be able to POST directly to the provider.
我认为您在“ $ fields”数组中没有此信息,因此无法直接过帐到提供程序。
What you want to look at is probably a callback from the provider's website once the payment is successful and complete. 付款成功完成后,您可能要查看的是提供商网站上的回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.