[英]shopping cart in php with session & database
I had developed a shopping cart in PHP using sessions and a database. 我使用会话和数据库在PHP中开发了一个购物车。
If the user is not logged in (a guest), the cart items are stored in the $_SESSION["cart"]
variable. 如果用户未登录(访客),则购物车项目存储在
$_SESSION["cart"]
变量中。
If the user is logged in, all of the cart items from the $_SESSION["cart"]
(if any) are copied to database and any previous cart items from database (if any) are also copied back to $_SESSION["cart"]
. 如果用户已登录,则将
$_SESSION["cart"]
(如果有)中的所有购物车项目都复制到数据库中,并且还将数据库中的所有先前的购物车(如果有)都复制回到$_SESSION["cart"]
。 Here I'll keep the copies both in the session and the database. 在这里,我将把副本都保留在会话和数据库中。
As long as user is logged in i don't have the problem with the cart items. 只要用户登录,我就不会遇到购物车项目的问题。
Since I am using session for guests, I'll certainly lose the cart details as soon as browser is closed. 由于我正在为访客使用会话,因此,我肯定会在关闭浏览器后丢失购物车详细信息。
How can I overcome this scenario? 如何克服这种情况?
I am trying to store guest cart details in a database, with a unique cookie value. 我正在尝试使用唯一的cookie值将访客购物车详细信息存储在数据库中。 Suggestions please?
有什么建议吗? cart Table Details :
购物车表详细信息:
cart_id*
user_id
product_id
product_option_id
product_count
total_amount
time_stamp
user_id+product_id+product_option_id is Unique
Here is the program flow that I would make. 这是我要制作的程序流程。 It's vague so you can implement it however you want to.
它含糊不清,因此您可以根据需要实施它。
Math.random()
. Math.random()
一样简单。 $_COOKIE["carts"]
with that session ID. $_COOKIE["carts"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.