当前位置: 动力学知识库 > 问答 > 编程问答 >

Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)

问题描述:

I have been playing around with cURL trying to pass POST data to a page payment gateway page...

I haven't been able to emulate a submit form action... I would like to forward the client to the payment gateway page (together with the POST data) but I can not find the way of doing this...

I do manage to pass the POST data, but the resulting page loads within my domain (instead of forwarding the user to the payment gateway).

$connection = curl_init("https://paymentgateway.com/script");

curl_setopt($connection, CURLOPT_RETURNTRANSFER, 0);

curl_setopt($connection, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($connection, CURLOPT_POST, 1);

curl_setopt($connection, CURLOPT_POSTFIELDS, $postdata);

curl_exec($connection);

curl_close($connection);

How should this be done?

网友答案:

Nearly all low-end payment gateway solutions expect you to actually carry out a POST to their server, at which point they'll take the payment details from the end user prior to returning the user to a designated page(s) with some status information. As such, using CURL is liable to cause problems.

What you probably need to do is output the relevant form via PHP into a (very) minimal HTML page with automatically causes the form to be submitted via the use of onload.

For example, if your form had an id of "checkoutform", you could use:

<body onload="document.getElementById(\'checkoutform\').submit();">

This is, of course, pretty poor. (Yet sadly inevitable.)

分享给朋友:
您可能感兴趣的文章:
随机阅读: