0

我从 paypal 中获取了标准的 IPN.php 示例,在 php 脚本中添加了错误处理和 mysqlconnection/mysqlquery。我相信它们可能是变量进入 ipn 脚本然后存储在 mysql db 中的问题。Mysql 数据库连接工作正常。我真的认为它的代码带有mysql查询,但我不知道如何更改它。任何帮助都是极好的!

通过 ipn_errors.log 出错

[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: item_number in /var/www/ipn.php on line 78
[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: payment_status in /var/www/ipn.php on line 78
[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: payment_amount in /var/www/ipn.php on line 78
[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: payer_email in /var/www/ipn.php on line 78

ipn.php- 正在创建这些错误。

// STEP 1: Read POST data

// reading posted data from directly from $_POST causes serialization 
// issues with array data in POST
// reading raw POST data from input stream instead. 
mysql_connect("localhost", "#####", "#####") or die(mysql_error());  
mysql_select_db("#####") or die(mysql_error()); 
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
 $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
    $value = urlencode(stripslashes($value)); 
} else {
    $value = urlencode($value);
}
$req .= "&$key=$value";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

// assign posted variables to local variables
$payer_email = $_POST['payer_email'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
 ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
}
 mysql_query("INSERT INTO paypalpayments (itemnum, paystatus, payamount, email) VALUES ('', '$item_number', 

'$payment_status', '$payment_amount',  '$payer_email')");
?>
4

1 回答 1

1

变量在这一行中设置:

$myPost[$keyval[0]] = urldecode($keyval[1]);

...后来在它$_POST用来复制变量的脚本中,如下所示:

$payer_email = $_POST['payer_email'];

建议:使用$myPost代替$_POST来定位这些变量。并且不要忘记 INSERT 查询之前的 mysql_real_escape_string() 。

如果ob_start()在顶部和$msg = ob_get_clean()末尾使用,则可以在调试此异步脚本方面取得一些进展。然后你有一个变量字符串,你可以通过电子邮件发送给自己。这将使您能够使用var_dump()等来发出诊断消息。

于 2013-01-21T19:10:21.543 回答