对于我尝试从 Paypal 表单字段中分配给变量的任何帖子,我都会返回“未定义索引”,例如: $item_number = $_POST['item_number'];
如果我对其进行硬编码 $item_number = 1; 然后它工作。
我在下面使用 Micah Carrick 脚本:任何想法为什么会发生这种情况?
<?php
/*
ipn.php - example code used for the tutorial:
PayPal IPN with PHP
How To Implement an Instant Payment Notification listener script in PHP
http://www.micahcarrick.com/paypal-ipn-with-php.html
(c) 2011 - Micah Carrick
*/
// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
// intantiate the IPN listener
include('ipnlistener.php');
$listener = new IpnListener();
// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = true;
// try to process the IPN POST
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
if ($verified) {
$item_number = $_POST['item_number'];
$to = "myEmail@blah.com";
$subject = "Paypal IPN Test";
$message = "Email sent successfully";
$message .= $item_number;
mail($to,$subject,$message,$listener->getTextReport());
}
else {
// manually investigate the invalid IPN
mail('myEmail@blah.com', 'Invalid IPN', $listener->getTextReport());
}
?>