繁体   English   中英

PHP cURL发布并显示外部页面

[英]PHP cURL Post to and display of External Page

我正在尝试重建一个当前向用户提供表单的网站,让用户单击一个按钮发布到基于输入数据进行一些计算的页面,然后让他们点击另一个按钮发布到付款供应商,使用输入的非敏感数据出示安全的付款表格。

我正在尝试执行以下操作。 我写了一个页面,展示了用于输入客户数据的表单,他们单击了一个提交按钮,将其发布到我网站上的php文件中,进行所需的计算,然后使用Curl发布到该网站。

过去,我仅使用cURL发布到网站,检查状态良好,然后继续。 是否可以像在我直接向表单提交表单时那样,使用Curl在浏览器中发布并转到其他页面?

综上所述:

  1. 我可以将其发布到Curl中的表单,并且使其具有与我将HTML表单中的操作设置为外部网站url时所发布的表单一样的作用。

  2. 如果是这样,我想念的是什么?

这是来自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);

将用户重定向到安全支付提供商的想法是,他/她将输入一些敏感的支付信息(抄送,到期等)以进行处理。 我认为您在“ $ fields”数组中没有此信息,因此无法直接过帐到提供程序。

付款成功完成后,您可能要查看的是提供商网站上的回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM