当会话 ID 已知但无法启动会话时删除会话变量
我在处理 paypal 和 ipn 时尝试删除一些会话变量的方式有问题.特别是,我想让某人登录(或不登录)我的在线零售店,查看我的购物车,被重定向到 paypal 进行付款,然后被重定向到我的网站.
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.
我一直在使用 paypal ipn 来让 paypal 在付款完成时通知我,我可以将用户引导回我的网站,在那里可以再次开始会话,但我希望能够取消购物车(但是不是整个会话,以防他们登录)一旦付款完成.这将涵盖我的基础,以防用户没有回到我网站上的付款完成页面,而是在不同页面上返回网站.
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.
问题是,尽管我在转到贝宝之前在我网站上的最后一个运输信息页面上获得了相同的会话 ID,并且在付款完成后从贝宝返回到我的网站的登录页面我无法访问此会话在我的网站上运行以响应贝宝的 ipn 脚本中.我在这三个页面中的每个页面上都运行 session_start() 但是当我在运输方式页面和付款完成登录页面上发送电子邮件或发布时,我得到了相同的会话 ID.当我通过电子邮件将会话 ID 在我的 ipn 脚本中的结果通过电子邮件发送给自己时,我什么也没有得到.
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.
我可以在去 paypal 之前杀死购物车,但如果他们想回去改变东西怎么办?我可以杀死登陆页面上的购物车,但如果他们以某种方式进入不同的页面怎么办?当我收到付款确认时,我真的很想销毁购物车而不是整个会话,但我不确定如何.我在我的 ipn 页面上试过这个:
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("webmaster@mysite.com", "ipn session id 0", $a, "From: webmaster@mysite.com");
//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.
推荐答案
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.
相关文章