如何在IPN脚本中提取自定义字段值?

时间:2013-09-10 21:29:20

标签: php paypal paypal-ipn

我在我的dayz服务器上运行IPN,以自动处理捐款并分发该人购买的任何好东西。虽然有一个问题...我添加了一个名为“播放器ID”的自定义字段,并且要求它们填写它,因为它稍后在数据库条目中使用。我的shopping.php页面如下所示:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">  
    <input type="hidden" name="cmd" value="_xclick">  
    <input type="hidden" name="business" value="myemail@gmail.com">  
    <input type="hidden" name="item_name" value="Alice Pack">  
    <input type="hidden" name="item_number" value="300">  
    <input type="hidden" name="amount" value="0.10">  
    <input type="hidden" name="no_shipping" value="0">  
    <input type="hidden" name="no_note" value="1">  
    <input type="hidden" name="currency_code" value="CAD">  
    <input type="hidden" name="lc" value="AU">  
    <input type="hidden" name="bn" value="PP-BuyNowBF">  
    <table>
<tr><td><input type="hidden" name="on0" value="Player Unique ID">Player Unique ID</td></tr><tr><td><input type="text" name="os0" maxlength="200"></td></tr>
</table>
    <input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">  
    <img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">  
</form> 

现在,我看到输入字段名为“os0”,所以我尝试mysql_real_escape_string($_POST['os0'])并且它什么也没有返回。

这是我的IPN.php:

<?php  

mysql_connect("dbhost", "dbuser", "dbpass") or die(mysql_error());  
mysql_select_db("db") or die(mysql_error());  

// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// post back to PayPal system to validate  
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";  
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";  
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);  
if (!$fp) {  
// HTTP ERROR  
} else {  
fputs ($fp, $header . $req);  
while (!feof($fp)) {  
$res = fgets ($fp, 1024);  
if (strcmp ($res, "VERIFIED") == 0) {  
    $id = mysql_real_escape_string($_POST['item_number']);
    $uniqueid = mysql_real_escape_string($_POST['os0']);
// PAYMENT VALIDATED & VERIFIED!  
mysql_query("INSERT INTO cust_loadout_profile (cust_loadout_id, unique_id) VALUES ('$id', '$uniqueid')");
$to      = 'myemail@gmail.com';  
$subject = 'Download Area | Login Credentials';  
$message = ' 

Thank you for your purchase 

Your account information 
------------------------- 
Email: '.$id.' 
Password: '.$password.' 
------------------------- 
             SUCCESS
You can now login at http://yourdomain.com/PayPal/';  
$headers = 'From:noreply@yourdomain.com' . "\r\n";  

mail($to, $subject, $message, $headers);  
}  

else if (strcmp ($res, "INVALID") == 0) {  

// PAYMENT INVALID & INVESTIGATE MANUALY!  
  $to      = 'myemail@gmail.com';  
$subject = 'Download Area | Login Credentials';  
$message = ' 

Thank you for your purchase 
 THIS IS ALSO AN ERROR
Your account information 
------------------------- 
Email: '.$email.' 
Password: '.$password.' 
------------------------- 

You can now login at http://yourdomain.com/PayPal/';  
$headers = 'From:noreply@yourdomain.com' . "\r\n";  

mail($to, $subject, $message, $headers);  
}  
}  
fclose ($fp);  
}  
?> 

有没有办法让我的帖子在我的IPN中工作?

1 个答案:

答案 0 :(得分:0)

您需要在表单中添加自定义字段,例如

&LT; input type =“hidden”name =“custom”value =“2”&gt;

并在ipn脚本上获取此字段使用下面的代码

&LT; ?PHP的

if(isset($ _ REQUEST ['custom'])){

$ custom = $ _REQUEST ['custom'];

}

&GT;

相关问题