php 购物车

发布于 2024-09-24 16:08:52 字数 183 浏览 0 评论 0原文

我正在做一个购物车,一切都很顺利,直到我意识到一些事情。目前我正在使用会话将用户的购物车项目跟踪到数据库中。用户无需登录即可将商品添加到购物车。但是,在结帐之前,用户需要登录才能进行操作。当用户登录时,session_id()将被重新生成。这意味着它将与用于存储 b4 登录的购物车项目的 session_id 不同。那么我该如何跟踪用户购物车物品呢?

im doing a shopping cart and everything works well until i realise something. currently im using session to track user's cart items into the database. user can add items to cart without login. however, before checkout, users will need to login to do so. when user login, the session_id() will be re-generated. this means that it will be different from the session_id used to store those cart items b4 login. how am i gonna track user cart items then??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千紇 2024-10-01 16:08:52

您可以在用户登录时定义 session_id - 使用与“未登录”会话相同的会话 ID 创建“已登录”会话。

http://www.php.net/manual/en/function。会话id.php

You could define the session_id when logging-in the user - creating the "logged in" session with the same session ID as the "not logged in" session.

http://www.php.net/manual/en/function.session-id.php

嘿看小鸭子会跑 2024-10-01 16:08:52

有两种方法,

1)您可以按照 matthewh 的建议维护相同的会话

2)您可以使用会话 id 在数据库中维护购物详细信息

希望这会有所帮助。

There are two ways,

1) You can maintain same session as suggested by matthewh

2) You can maintain shopping details in database with session id

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文