设置POST变量和重定向页面


Setup POST variables and the Redirect Page

我目前有一个标准的paypal表单,它张贴到paypal并收取金额。然而,这些细节可以很容易地被用户修改。所以,我想知道我是否可以做以下事情:

代替我的'Finish &支付按钮直接进入paypal,按钮的形式是指向我的网站。

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

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

编辑——这并不工作

试试这个:

// 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");

初始发布

你可以使用curl:

$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);