session失效,很奇怪的失效
這兩天一直在寫paypal, 現在就快把ipn.php整完了,但遇到一個問題讓我很費解啊!
session在ipn.php裡面只有一部分有效,看代碼
PHP code
connect();$listener = new IpnListener();$listener->use_sandbox = true;$order_time=$_SESSION['order_time_org'];$username=$_SESSION['user'];echo "$order_time, $username";//到這裡位置以上,SESSION是可以用的 上面輸出兩個都能顯示出來//下面就顯示不出來了!這是為什嗎?try { $verified = $listener->processIpn();} catch (Exception $e) { // fatal error trying to process IPN. exit(0);}if ($verified) { // IPN response was "VERIFIED" //send email form $invoice_id=$_POST['invoice']; $payment_status = $_POST['payment_status']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; //$order_time = $_POST['custom']; //$whimwin_user=$_SESSION['user']; //這裡的$_SESSION['user']顯示不出來啊! //if($payment_status=="Completed") //{ $query="UPDATE CART SET payment_status='paid' WHERE username='$username' AND order_time='$order_time' AND invoice_id='$invoice_id'"; $result=queryMysql($query); if($result) { $to="[email protected]";//payer_email //subject $subject="Whim Win paid successful!"; //from $header="from: test <[email protected]>"; //message body $message="Dear Member, \n\n"; $message.="this is you invoice id $invoice_id \n"; $message.="$payment_status, $order_time, $payer_email, $receiver_email, $username"; //send email $sendmail=mail($to,$subject,$message,$header); } //}} else { // IPN response was "INVALID"}$db->close();?>
------解決方案--------------------
先測試一下
try {
print_r($_SESSION);
$verified = $listener->processIpn();
print_r($_SESSION);
} catch (Exception $e) {
// fatal error trying to process IPN.
exit(0);
}
------解決方案--------------------
不要去管他,自己緩衝一下
先調通了再說
try {
$mysession = $_SESSION;
$verified = $listener->processIpn();
$_SESSION = $my_session;
} catch (Exception $e) {
// fatal error trying to process IPN.
exit(0);
}
------解決方案--------------------
你這個ipn.php檔案是支付成功的verify頁面吧?我有看到你update支付狀態的sql語句。
如果我猜的沒錯,那麼你要搞清楚的一點是,客戶支付的過程是走瀏覽器,所以cookie頭可以續傳,但是paypal請求你這個頁面通告你支付結果這個流程,是通過palpay服務端完成的,比如我們php常用的curl。所以如果你不是顯式的傳給paypal當前的cookies,然後paypal請求的header頭裡帶上這個cookies,怎麼可能讀到session呢。