doutan3192 2014-04-27 09:34
浏览 18
已采纳

如何通过访问会话信息超时会话并在超时前执行操作?

I am storing the items of shopping cart into a session array, but since the product ids and quantity is being stored on the client side , I can't perform a check on the quantity of items when a customer wants to add an item whose available quantity is already added to other customers carts.

So I have added a column called added_to_cart in my Products table which increments when a product/item is added to a customers session cart.

Now I want to time out the session when there's no activity by the customer for an hour and decrement the added_to_cart by checking what's stored in the inactive(to be timed out)php session

    Products
    -----------------------------------------
    : p_id  : available_qty : added_to_cart :
    -----------------------------------------
    : p-123 :  57           : 3             :
    -----------------------------------------
    : p-287 :  32           : 8             :
    -----------------------------------------

1.Is it possible to do it when the customer doesn't visit the site ever after(i.e without calling the session_start()).If so how?.

2.Is it the right proposed solution?How do they do it in bigger online stored like amazon and ebay?

  • 写回答

1条回答 默认 最新

  • dongpi2503 2014-04-27 09:41
    关注

    You should do the FINAL quantity check when order is placed/submitted, not when added to cart. Think what happens, if somebody adds all products in your system to cart (just for fun).. your eCommerce shop would be sold out :)

    So should be like:

    • when viewing item available quantity (in stock quantity) use value from database (real, current, available quantity)
    • when order is submitted, check that the quantity ordered is available. If not, notify user. If is, make the reduction and save to DB.

    There is also lot of well maid, free eCommerce softwares available like: Magento (http://magento.com/)

    TIMED SESSIONS:

    But if you really want to do the session thing, you can:

    • save sessions to database with timestamp
    • update timestamp on every page request by user (like "last access")
    • periodically delete old session rows and "free" reserved products

    Keep in mind that the sessions (reserved products related) should then be quite short (like 30 minutes?).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计