2012-12-14 15 views
0

我有一個表單,它在提交時收集數據並在我的數據庫中寫入字段的值。該表單使用一個發佈請求到響應頁面,然後連接到數據庫並將所有必要的字段發佈到我的數據庫。表單發佈到數據庫以及PayPal

我也有一個單選按鈕稱爲付款,其中一個選項是貝寶。我的目標是最終發佈領域的分貝,而且下面的表格資料寄給我的PayPal帳戶中的一個去

<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
<input type="hidden" name="cmd" value="_xclick" /> 
<input type="hidden" name="business" value="myemails" /> 
<input type="hidden" name="currency_code" value="GBP" /> 
<input type="hidden" name="item_name" value="Digital Download" /> 
<input type="hidden" name="amount" value="9.99" /> 
<input type="hidden" name="return" value="http://myurl/form.htm" /> 
<input type="hidden" name="notify_url" value="http://myurl/example/ipn.php" /> 
<input type="image" src="btn_buynow_LG.gif" border="0" name="submit" alt="Paypal" /> 
</form> 

我知道我可以使用下面的下面的命令做一個重定向到另一個網頁,其中有一個形式

if($_REQUEST['payment']=="Paypal") { redirect to another page with the code above, but the user has to click on submit again} 

但是我只是想在用戶點擊提交一次,我的數據庫記錄的詳細信息,然後自動將其重定向到PayPal。

回答

1

這是相當瑣碎,只是做:

if($_POST['submit']) { 
    // save the POSTed data to the DB 
} 

// now for PayPal 
if($_POST['payment'] == "Paypal") { 
    // now connect to PayPal API and process a payment 
} 

我建議fogetting約$_REQUEST和使用ONLY$_GET和/或$_POST需要的地方。

+0

您的臨時數據,爲什麼忘記$ _REQUEST? – fdreger

+1

@fdreger這是一個潛在的漏洞,並允許攻擊者執行攻擊更容易... – shadyyx

+0

這似乎是最好的方式來做到這一點,除了我使用的ipn類看起來並不像它使用Paypal API [link] (http://www.micahcarrick.com/paypal-ipn-with-php.html) – JK36

-1

不知道理解你的問題,但你應該創建臨時數據到數據庫的頁面加載並在貝寶API回調打電話給你inp.php,變換在驗證一個

+0

我想存儲某人的預訂詳情,而不管他們是使用PayPal進行付款還是其他手動方式。因此,我的回覆頁面記錄了進行調查的人的詳細信息,然後我希望它重定向到貝寶網站(提供貝寶選擇付款選項) - 但聽起來像我需要使用api來做到這一點,而不是'form'方法 – JK36