PHP$\会话在try{}catch(){}块后清空
在我最终找到了一个非常有效的Paypal IPN脚本之后,我遇到了一个问题,在try{}catch{}块之后,$_会话清空 问题是IPN已经过验证,我对此有100%的把握。事实上,在try{}catch{}块之后,我从if块内部将errorsLogg到一个文件 这是密码PHP$\会话在try{}catch(){}块后清空,php,session,session-variables,session-state,Php,Session,Session Variables,Session State,在我最终找到了一个非常有效的Paypal IPN脚本之后,我遇到了一个问题,在try{}catch{}块之后,$_会话清空 问题是IPN已经过验证,我对此有100%的把握。事实上,在try{}catch{}块之后,我从if块内部将errorsLogg到一个文件 这是密码 include($_SERVER['WROOT'].'core/init.php'); $total = 0; $prodArray = array(); foreach($_SESSION['cart'] as $prod
include($_SERVER['WROOT'].'core/init.php');
$total = 0;
$prodArray = array();
foreach($_SESSION['cart'] as $prodID => $prodInfo) {
$product = getProduct($prodID, $dbh);
$currQty = 0; $itemTotal = 0;
foreach($prodInfo as $size => $qta) { $currQty += $qta; }
$itemTotal = ($product->sale_price != 0) ? $currQty * $product->sale_price : $currQty * $product->price;
$total += $itemTotal;
array_push($prodArray, $prodID);
}
$total = number_format($total, 2, '.', ',');
/*
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', 'logs/ipn_errors.log');
DEFINE('DEVELOPER_EMAIL', 'dev@email.com');
DEFINE('MERCHANT_EMAIL', 'merchant@email.com');
DEFINE('MC_GROSS', $total);
DEFINE('MC_CURRENCY', 'EUR');
// intantiate the IPN listener
include('core/classes/IpnListenerClass.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 ) {
$errmsg = ''; // stores errors from fraud checks
// 1. Make sure the payment status is "Completed"
if ( $_POST['payment_status'] != 'Completed' ) {
// simply ignore any IPN that is not completed
exit(0);
}
// 2. Make sure seller email matches your primary account email.
if ( $_POST['receiver_email'] != MERCHANT_EMAIL ) {
$errmsg .= "'receiver_email' does not match: ";
$errmsg .= $_POST['receiver_email']."\n";
}
// 3. Make sure the amount(s) paid match
if ( $_POST['mc_gross'] != $total ) {
$errmsg .= "'mc_gross' does not match: ";
$errmsg .= "$total\n";
$errmsg .= $_POST['mc_gross']."\n";
}
// 4. Make sure the currency code matches
if ( $_POST['mc_currency'] != MC_CURRENCY ) {
$errmsg .= "'mc_currency' does not match: ";
$errmsg .= $_POST['mc_currency']."\n";
}
// 5. Ensure the transaction is not a duplicate.
$checkTxn = $dbh->prepare(" SELECT txn_id FROM orders WHERE txn_id = :txn_id ");
$checkTxn->execute(array( 'txn_id' => Input::post('txn_id') ));
if ( $checkTxn->rowCount() == 1 ) {
$errmsg .= "'txn_id' already processed: ";
}
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$body .= $listener->getTextReport();
mail(DEVELOPER_EMAIL, 'Walking Outlet IPN Fraud Warning', $body);
} else {
// add this order to a table of completed orders
$orderDetails = array(
'txn_status' => Input::post('payment_status'),
'txn_id' => Input::post('txn_id'),
'user' => Session::getUser(),
'comments' => (!Input::emptyPost('memo')) ? Input::post('memo') : ''
);
$newOrder = $dbh->prepare("
INSERT INTO
orders(txn_status, txn_id, user, order_date, comments)
VALUES(:txn_status, :txn_id, :user, NOW(), :comments)
");
$newOrder->execute($orderDetails);
$orderID = $dbh->lastInsertId('id');
// add the ordered items to the table
foreach($_SESSION['cart'] as $prodID => $prodInfo) {
$product = getProduct($prodID, $dbh);
foreach($prodInfo as $size => $qta) {
$itemDetails = array(
'order_id' => $orderID,
'item_id' => $prodID,
'item_size' => $size,
'item_qta' => $qta
);
$newItem = $dbh->prepare("
INSERT INTO
order_items(order_id, item_id, item_size, item_qta)
VALUES(:order_id, :item_id, :item_size, :item_qta)
");
$newItem->execute($itemDetails);
}
}
// send seller an email with buyer information
$to = filter_var(DEVELOPER_EMAIL, FILTER_SANITIZE_EMAIL);
$subject = "Nuovo ordine effettuato";
$message = print_r($_SESSION);
mail($to, $subject, $message);
}
} else {
// manually investigate the invalid IPN
mail(DEVELOPER_EMAIL, 'Walking Outlet - Invalid IPN', $listener->getTextReport());
}
有什么建议吗?exit0代码不会执行,因为如果它会执行,我就不会从if块内部得到错误
编辑:所以我发布了我的全部代码 IPN脚本被自动paypal bot命中,您不应该在其中使用会话变量。您如何知道$\u会话为空?您没有在try/catch块之后引用它。很抱歉,我删除了代码,因为它太大了。我将更新代码。@Dagon问题是,我必须检查登录用户和购物车中的产品,以便能够检查来自PayPal的MTU总额是否正确,并在付款后将产品插入数据库,所有这些都是通过$会话完成的。你有什么建议?点击脚本的paypal机器人根本不知道你的用户会话!