在 paypal iPN 响应期间无法取消设置会话
当 PayPal 返回 IPN 时,我需要取消设置会话变量。
最简单的脚本是以下
<?php
session_start();
unset($_SESSION['my_item']);
?>
Paypal 发送 IPN,一切正常,但在请求后我的会话变量保存它的值。
有什么问题吗?
谢谢
更新
如前所述,当 ipn 发送请求时,它已经是另一个会话,所以我可以执行以下操作。
在将用户发送到 PayPal 之前,将自定义变量设置为当前
session_id();
当 paypal 发送 ipn 时,我可以将当前会话更改为上一个会话,并将其清除。
session_id($_POST[custom]);
session_start();
session_destroy(); //works fine
I need to unset my session variables, when PayPal returns IPN.
The simplest script is the following
<?php
session_start();
unset($_SESSION['my_item']);
?>
Paypal sends IPN, all works fine, but after request my session variable save it's value.
What can be a problem?
Thanks
UPDATE
As mentioned, when ipn sends request, it's already another session, so i can do the following.
Before send user to paypal, set custom variable to current
session_id();
When paypal sends ipn, i can change current session to previus session, and clear it.
session_id($_POST[custom]);
session_start();
session_destroy(); //works fine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里的问题是 IPN 通知未与正确的会话关联。
IPN 实际上是一个新会话 - 它不会提供与您的客户端相同的会话 cookie,因为您还没有设置它们。会话对于客户端来说是唯一的,并且 paypal 网关是与您的用户不同的客户端。
您将需要通过数据库退回此信息。没有明智、简单的方法可以让 IPN 接收器直接修改用户的会话数据。
The problem here is that the IPN notification is not associated with the correct session.
The IPN is effectively a new session - it does not present the same session cookies that your client does, because you have not set them. Sessions are unique to a client, and the paypal gateway is a different client to that of your user.
You will need to bounce this information through a database. There is no sensible, easy way to have the IPN receiver directly modify the user's session data.
您应该检查特定的后变量。 $_POST 将始终被设置,即使只是一个空数组。
You should be checking for a specific post variable. $_POST will always be set, even if just an empty array.
我已经写了更新,但是如果我将解决方案写为答案,它会更好。
如果我将 session_id 发送到 paypal,当它返回时,我可以将当前会话设置为其值,然后将其删除。
I've already write the update, but it will be batter, if i write the solution as answer.
If i send session_id to paypal, and when it returns it back, i can set my current session to it's vallue, and delete it.
如果你的条件是:
那么这应该有效:
Should your conditional be:
Then this should work: