我目前有一个自定义购物车直接发送到2Checkout,并需要使用不同的付款方式相同的形式。PHP重定向到其他网站与POST变量
要做到这一点,我需要先将表格提交给我自己的服务器,然后将服务器重定向到选定的支付网关或我网站上的一个页面,其中详细介绍了其他支付选项。
我该如何将变量作为PHP中的post方法(而不是javascript)重定向到用户?
我当前的代码不工作的用户不离开页面,他们需要......
//$url = 'https://www.2checkout.com/checkout/spurchase';
$url = 'getpost.php';
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); // RETURN THE CONTENTS OF THE CALL
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
http://stackoverflow.com/questions/3045097/php-redirect-and-send-data-via-post – mithunsatheesh 2013-02-11 13:11:04
你应该有一个表格,并提交它的值与你有。另一种方式是反对w3c规则,因为用户在他不知情的情况下被重定向。 – mithunsatheesh 2013-02-11 13:12:06