0
我想讓PHP腳本將用戶發送到已經預先配置好的PayPal頁面。基本上,我試圖擺脫中間頁面,「請等待,我送你到貝寶,等等」。使用PHP與fsockopen模擬PayPal _xclick
Currenly這是正在發生的事情:1。 用戶填寫其被POST'd我process.php頁 2.我想process.php建立_xclick串並直接張貼到貝寶和表演形式(重定向?)瀏覽器中的頁面。
這就是我現在正在做的事情,但是用戶的網絡瀏覽器沒有重定向。我知道我可以回顯一些HTML並使其起作用,但我認爲有一種方法可以獲取數據,但我想讓瀏覽器採取更多行動?
//create array of requuired minimal data for a PayPal button
$post_data['amount'] = '123';
$post_data['item_name'] = 'widget';
$post_data['item_number'] = '123';
$post_data['quantity'] = '123';
$post_data['currency_code'] = 'USD';
$post_data['business'] = '[email protected]';
$post_data['no_shipping'] = '2';
//traverse array and prepare data for posting (key1=value1)
foreach ($post_data as $key => $value)
{
$post_items[] = $key . '=' . urlencode(stripslashes($value));
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
// Add command string
$post_string = '?cmd=_xclick&' . $post_string;
// Connect to PAYPAL
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
//sending the data
fputs($fp, "POST /cgi-bin/webscr HTTP/1.1\r\n");
fputs($fp, "Host: www.paypal.com\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n");
fputs($fp, "\r\n");
fputs($fp, $post_string);
while (!feof($fp))
{
echo fgets($fp, 1024);
}
fclose($fp);
要添加;這不僅僅是PayPal:你無法將服務器端POST發送到某個地方,然後將買家重定向到某個地方,因爲買家不會被綁定到之前發送的POST數據。正如你所提到的,快速結賬是最好的解決方案。 – Robert