dongpu8935 2011-08-08 21:13
浏览 321
已采纳

将购物车项目存储到cookie和数据库中

I am working on an e-commerce website. When the user is not logged into my website and clicks on "Buy Now" button, I want to store this information into the cookie as well as in the database. The table for the shopping cart looks like

SHOPPING_CART 
(
     sessionid   int(10), 
     itemid      int(10), 
     quantity    tinyint(10) unsigned
     date_added  datetime
);

Primary key is: (sessionid, itemid)

When the user closes the browser then also the shopping cart items should be preserved. Now my question is the following:

  1. When the user is not logged into my website, on what basis I should identify the user?
  2. Should I store the information using the IP address? If yes then HOW? In this case sessionid in the above mentioned table would be the IP address of the user. Right?
  3. Should I create a temporary session for each and every user who visits my website and then store the information? If yes then HOW?
  4. How can the shopping cart items be preserved even when the user closes the browser window? Should I retrieve from database or cookie?
  5. Any other better method to store and retrieval of the information?

Note1: I can use plenty of Shopping Cart softwares/codes/libraries available. But I want to know: How to identify the user? And storing/retrieval of data.

Note2: The price of each item, ordering, shipping information all are stored in different tables.

  • 写回答

2条回答 默认 最新

  • duanniedang3946 2011-08-08 21:23
    关注
    1. All you can do is create a unique fake identity for the user
    2. No. Multiple users may have the same IP address, and a single user may change its IP address
    3. Yes. PHP will create a session for you as soon as you ask to start a session. You must associate an identity with this session. Just use a random number, or a UUID generator, or something like that to generate something unique and not easily guessable. Then store the identity in a cookie so that when the user comes back some time later, you can re-associate his identity with the new session.
    4. I would just store the identity in the cookie. A cookie only holds a small amount of information, and may be modified by the user without you knowing it.
    5. If the users don't log in, I don't see any other way.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答