开发者

SESSION variables are being destroyed during Paypal IPN process

开发者 https://www.devze.com 2023-02-09 18:22 出处:网络
My problem is that my SESSION variables are being destroyed during the Paypal IPN process. I have successfully written my IPN listener to talk to Paypal and I have no problem manipulating the predefi

My problem is that my SESSION variables are being destroyed during the Paypal IPN process.

I have successfully written my IPN listener to talk to Paypal and I have no problem manipulating the predefined IPN variables that Paypal POST’s back to me. Despite this, I am having trouble accessing the SESSION variables created before the Paypal payment is made. I assume that they are being destroyed when I connect to Paypal.

I have quite a few variables so it is not feesable to just use Paypal’s ‘custom’ field.

As an example, if I want to send an email to a customer containing a SESSION variable (named $_SESSION[‘order_type’] ) that they created during the ordering process on my site:

<?php

//enable sessions
if (!isset($_SESSION)) {
  session_start();
}

**** Accept payment/verify 开发者_StackOverflow中文版using paypal listener etc****

// If everything is successful and the payment is accepted then send an email containing some previously stored session variables

   $mail_From = "From: me@example.com";
   $mail_To = "email@email.com";
   $mail_Subject = "Your payment has been made successfully” ;
   $mail_Body = "you have successfully made a ". $_SESSION['order_type']."order";
   mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

   ?>

My email never contains my session variables leading me to believe that they are being destroyed...please help!

Many thanks,

David


You could create a session save handler to store all your session data in a database. Pass on the session ID to PayPal in the custom field and restore the session on return from PayPal.

Start from the example at http://nl.php.net/manual/en/function.session-set-save-handler.php


Session is unique to client. Your PayPal IPN listener handles message sent from Paypal, which is not from your browser. So technically, it is not in the same "SESSION" of your payment process. Every session variables set in your payment process are invisible in the IPN listener codes.

To solve this problem, you can store all the variables together with the "transaction id" into a database (or a file) in the payment process. And retrieve them out later in IPN listener based on that transaction id.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号