代码一直工作到3号检查,然后当我将它们导入数据库时,我得到一个空行或者有时没有。当我使用
if($ _SERVER ['REQUEST_METHOD']!=“POST”)die(“No Post Variables”);
顶部的代码,我得到“No Post Variables”但我可以使用post变量来检查是否有错误。我看到从ipn返回的item变量,因为我可以使用它们但是当我将它们导入数据库时它们不会出现。
为什么我不能将它们添加到数据库?
我一直在为这个IPN工作一周而没有结果。
if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables");
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$url = "https://sandbox.paypal.com/cgi-bin/webscr";
//$url = "https://www.paypal.com/cgi-bin/webscr";
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);
$req = str_replace("&", "\n", $req);
// Check Number 1 ------------------------------------------------------------------------------------------------------------
$receiver_email = $_POST['receiver_email'];
if ($receiver_email != "samuel_1347268213_biz@hotmail.com") {
$message = "Investigate why and how receiver email is wrong. Email = " . $_POST['receiver_email'] . "\n\n\n$req";
mail("@hotmail.com", "Receiver Email is incorrect", $message, "From: samuel_1347268213_biz@hotmail.com" );
exit(); // exit script
}
// Check number 2 ------------------------------------------------------------------------------------------------------------
if ($_POST['payment_status'] != "Completed") {
// Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete
mail("@hotmail.com", "payment_status", $message, "From: samuel_1347268213_biz@hotmail.com" );
}
// Connect to database ------------------------------------------------------------------------------------------------------
require_once 'connect_to_mysql.php';
// Check number 3 ------------------------------------------------------------------------------------------------------------
$payer_email = $_POST['payer_email'];
$sql = mysql_query("SELECT * FROM transactions WHERE payer_email= '".$payer_email."' LIMIT 1");
$numRows = mysql_num_rows($sql);
if ($numRows > 0) {
$message = "Duplicate transaction ID occured so we killed the IPN script. \n\n\n$req";
mail("@hotmail.com", "Duplicate txn_id in the IPN system", $message, "From: samuel_1347268213_biz@hotmail.com" );
exit(); // exit script
$txn = $_POST['txn_id'];
$payer = $_POST['payer_email'];
$l = "INSERT INTO transactions (txn_id,payer_email)VALUES ('".$txd ."','".$payer ."')";
mysql_query($l)or die;
// Mail yourself the details
$req .= "\n\nDataverified from Paypal!";
mail("@hotmail.com", "NORMAL IPN+++ RESULT", $req, "From: samuel_1347268213_biz@hotmail.com");