session失效,很奇怪的失效解決方案

來源:互聯網
上載者:User
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呢。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.