当会话ID已知但无法启动会话时删除会话变量 [英] delete session variables when session id is known but not able to start session

查看:77
本文介绍了当会话ID已知但无法启动会话时删除会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在处理Paypal和ipn时尝试删除一些会话变量的方式存在问题.具体来说,我想让某人登录(或不登录)我的在线零售商店,并通过购物车,重定向到贝宝付款,然后重定向到我的网站.

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.

问题是,尽管我在进入Pay​​pal之前在网站上的最后一个运输信息页面上都获得了相同的会话ID,并且在付款完成后从Paypal回到了我的网站的登陆页面,但我无法访问此会话在我的ipn脚本中,该脚本在我的网站上运行以响应Paypal.我在这三个页面中的每个页面上都运行session_start(),但是当我通过电子邮件发送或张贴在送货方式页面和付款完成目标页面上时,我得到了相同的会话ID.当我通过电子邮件将自己的ipn脚本中会话ID的结果发送给自己时,我什么也没得到.

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.

我可以在付钱之前杀死购物车,但是如果他们想回去改变东西怎么办?我可以在目标网页上杀死购物车,但是如果他们以某种方式到达另一页怎么办?当我收到付款确认书时,我真的很想破坏购物车,而不是整个会话,但是我不确定如何.我已经在我的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中的用户会话相关的任何操作.每个用户都有自己的会话,您不能编辑其他任何人的会话.在这种情况下,您的用户拥有一个会话,贝宝(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.

这篇关于当会话ID已知但无法启动会话时删除会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆