开发者

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($conn开发者_StackOverflow社区ection);
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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜