Paypal IPN 如何获取当前会话

发布于 2024-09-06 16:40:54 字数 938 浏览 3 评论 0原文

我想要将我之前的 $_SESSION['cart'] 获取到

IPN 代码 我使用。一切正常,脚本从 Paypal 获取了 $_POST 数据。

if (strcmp ($res, "VERIFIED") == 0) {
        $subject = time();
        $to      = '[email protected]';
        foreach ($_POST as $key => $value) { 
        $body .= "\n$key: $value";
        }
        mail($to, $subject, $body); 
}

问题

if (strcmp ($res, "VERIFIED") == 0) {
 // 1. How to get my previous $_SESSION['cart'] here? 
 // 2. When I call my $_SESSION['cart'] here not ouput will come & it's empty.
 // 3. Or this code only to get $_POST data from Paypal website only?
}

I want to get my previous $_SESSION['cart'] to the Paypal IPN

Sample of IPN Code I use. Everything working fine and script got the $_POST data from Paypal.

if (strcmp ($res, "VERIFIED") == 0) {
        $subject = time();
        $to      = '[email protected]';
        foreach ($_POST as $key => $value) { 
        $body .= "\n$key: $value";
        }
        mail($to, $subject, $body); 
}

Question

if (strcmp ($res, "VERIFIED") == 0) {
 // 1. How to get my previous $_SESSION['cart'] here? 
 // 2. When I call my $_SESSION['cart'] here not ouput will come & it's empty.
 // 3. Or this code only to get $_POST data from Paypal website only?
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖正好 2024-09-13 16:40:54

您不能这样做,因为 IPN 是在您的结账流程之外收到通知的。它本质上是一个独立于网站订购/支付过程的后台操作。如果您需要访问该会话中的信息,则需要将其存储在数据库中,然后包含某种标识符,该标识符也会传递给 Paypal。电子邮件地址通常很好,但唯一的标记(例如某种哈希值)可能更好。然后,当 IPN 通知带有该标识符时,您可以从数据库中提取该信息并根据需要使用。

You can't because IPN is notified outside of your checkout process. It essentially is a background operation separate from the ordering/payment process of your website. If there is information in that session that you need to access you will need to store it in a database and then include some kind of identifier with it that is also passed to Paypal. Email addresses are usually good but a unique token, like a hash of some kind, is probably better. Then when the IPN notification comes in with that identifier you can pull that information out of the database and use as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文