当会话 ID 已知但无法启动会话时删除会话变量
我在处理 paypal 和 ipn 时尝试删除一些会话变量的方式有问题。具体来说,我想让某人登录(或未登录)我的在线零售商店,浏览我的购物车,进行重定向到 paypal 付款,然后重定向到我的网站。
我一直在使用 paypal ipn 让 paypal 在付款完成时通知我,我可以将用户引导回我的网站,在那里可以再次启动会话,但我希望能够取消设置购物车(但不是整个)付款完成后立即会话(如果他们已登录)。这将是为了覆盖我的基础,以防用户没有返回我网站上的付款完成页面,而是返回到其他页面上的网站。
问题是,虽然我在转到 paypal 之前在我网站上的最后一个运输信息页面上获得相同的会话 ID,并且在付款完成后从 paypal 返回我的网站的登陆页面,但我无法在我的 ipn 中访问此会话在我的网站上运行以响应 paypal 的脚本。我在这三个页面上运行 session_start() ,但是当我在送货方式页面和付款完成登陆页面上发送电子邮件或发布时,我得到相同的会话 ID。当我通过电子邮件向自己发送 IPN 脚本中会话 ID 的结果时,我什么也没得到。
我可以在去贝宝之前杀掉购物车,但如果他们想回去改变东西怎么办?我可以在登陆页面上杀死购物车,但如果他们以某种方式进入不同的页面怎么办?当我收到付款确认时,我真的很想销毁购物车,但不是整个会话,但我不知道如何销毁。我在我的 iPN 页面上尝试过这个:
session_start();
$a = session_id();
mail("[email protected]", "ipn session id 0", $a, "From: [email protected]");
//results in blank email, unlike in other locations on actual displayed pages
// Unset all of the session variables.
$_SESSION = array();
// Delete the session cookie to kill the session
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
unset($_SESSION['cart']);
unset($_SESSION['product_id_array']);
unset($_SESSION['pp_checkout_btn']);
unset($_SESSION['state']);
unset($_SESSION['total']);
unset($_SESSION['shipping']);
unset($_SESSION['grand_total']);
但是当我返回查看购物车页面时,它仍然在那里。任何想法将不胜感激。任何有帮助的更具体的代码,请告诉我,我会将其发布。
i am having a problem with the way that i am trying to delete some session variables when dealing with paypal and ipn.specifically, i want to have someone logged in (or not) at my online retail store, go through my cart, get redirected to paypal for payment, and then get redirected to my site.
i have been using paypal ipn to get paypal to notify me when the payment is complete and i can direct the user back to my site where the session can be started again, but i want to be able to unset the cart (but not the entire session in case they are logged in) as soon as the payment is complete. this would be to cover my bases in case the user does not land back on the payment completed page on my site but gets back on the site on a different page.
the problem is that although i am getting the same session id both at the last shipping info page on my site before going to paypal, and the landing page back on my site from paypal when the payment is completed i cannot access this session in my ipn script that runs on my site in response to paypal. i am running session_start() on each of these three pages but when i email or post on the shipping method page and the payment complete landing page i get the same session id. when i email myself the result of session id in my ipn script, i get nothing.
i could kill the cart before going to paypal but what if they wanted to go back and change things? i could kill the cart on the landing page, but what if they get to a different page somehow? i would really like to destroy the cart but not the entire session right when i get payment confirmation but i am not sure how. i have tried this on my ipn page:
session_start();
$a = session_id();
mail("[email protected]", "ipn session id 0", $a, "From: [email protected]");
//results in blank email, unlike in other locations on actual displayed pages
// Unset all of the session variables.
$_SESSION = array();
// Delete the session cookie to kill the session
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
unset($_SESSION['cart']);
unset($_SESSION['product_id_array']);
unset($_SESSION['pp_checkout_btn']);
unset($_SESSION['state']);
unset($_SESSION['total']);
unset($_SESSION['shipping']);
unset($_SESSION['grand_total']);
but when i go back to the view cart page, it is still there. any ideas would be greatly appreciated. any more specific code that would help, let me know and i will post it up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Paypal IPN 调用由 Paypal 发起,并且仅限于服务器到服务器。您也不知道 IPN 呼叫何时打来。通常它们会在几秒钟内发生,但也可能会晚得多。如果IPN呼叫失败,他们将重试一段时间。您无法执行与 IPN 中的用户会话相关的任何操作。每个用户都有自己的会话,您无法编辑其他人的会话。在这种情况下,您的用户有一个会话,而 Paypal(IPN 调用)获得它自己的会话。
付款成功后,您必须在返回网站时清除会话变量。这并不是万无一失的——购物车仍然有可能无法被清除,但这几乎是唯一的方法。
The Paypal IPN call is made by Paypal and is server-to-server only. You also don't know when that IPN call is coming. Usually they happen within seconds, but they can come much later. If the IPN call fails, they will retry again for some time. You cannot do anything related to the users session in the IPN. Each user has it's own session and you can't edit anyone else's. In this situation, your user has a session, and Paypal (the IPN call) gets it's own session.
You'll have to clear the session variables on the return to your site after successful payment. It's not foolproof - there are possibilities that the cart still won't be cleared, but this is pretty much the only way to do it.