PHP 上的 Session_ONEEnd
我最近开始使用 PHP 进行编程。
我正在用 PHP 构建一个购物车。当有人将我的产品添加到购物车时,我将其锁定在购物车中。
当特定用户注销或会话过期时,我需要解锁这些产品。
我如何调用像 asp/asp.net 中的 session_onend 函数来解锁/释放那些锁定的产品?
I have recently started programming in PHP.
I am building a cart in PHP. I have my products locked in cart when someone adds it to their cart.
I need to unlock those products when the specific user gets logoff or session expires.
How can i call something like session_onend function as in asp/asp.net to unlock/release those locked products?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以编写自定义会话处理程序并实现您自己的垃圾收集器。
http://www.php.net/manual/ en/function.session-set-save-handler.php
但我建议不要这样锁定。它会弄乱你的库存。因为只有少数人会真正购买他们的购物车。
You can write a custom session handler and implement your own garbage collector.
http://www.php.net/manual/en/function.session-set-save-handler.php
But I would advise against such a locking. It will mess your stock. As only a few people will buy their cart load in real.
为什么不在实际下订单时消耗库存产品呢?保留产品直到用户填写正确的计费信息,然后在一切正常后减少库存?
Why not consume the product from stock when the order is actually placed. Hold the product until the user fills out the correct info for billing, then reduce inventory when all goes correctly?