0

我目前有一个标准的贝宝表格,它张贴到贝宝并收取一定的费用。然而,这些细节可以很容易地被用户修改。所以,我想知道我是否可以执行以下操作:

而不是我的“完成和支付”按钮直接转到贝宝,按钮的形式指向我的网站。

然后我的网站 PHP 代码设置了 POST 变量(地址、姓名、金额、业务、return_url 等),然后将页面重定向到贝宝网站。

PHP怎么可能做到这一点?到目前为止,我知道要做的唯一代码是使用该header()函数来重定向页面,但我不知道如何设置 POST 变量。

4

1 回答 1

0

编辑 - 这不起作用

尝试这个:

// Set Data
$data = array();
$data['address'] = $_POST['address'];
$data['name'] = $_POST['name'];
//  the other info ....

// Send post data as url-encoded in the header
$req = http_build_query($data);

header("method: POST\r\n");
header("Host: localhost\r\n");
header("Content-Type: application/x-www-form-urlencoded\r\n");
header("Content-Length: ".strlen($req)."\r\n");
header($req."\r\n\r\n");
header("Connection: close\r\n\r\n");

header("Location: http://paypal.com/path/\r\n");

初始帖子

你可以使用卷曲:

$ch = curl_init('http://paypal.com/path/');

// Set Data
$data = array();
$data['address'] = $_POST['address'];
$data['name'] = $_POST['name'];
//  the other info ....

// Set options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute
$page = curl_exec($ch); 
于 2013-04-22T11:48:26.930 回答