Remove expired items from the php shopping cart

Source: Internet
Author: User
Php shopping cart to delete expired items now has a small product system, so that the shopping cart process is clear. I did this: when a visitor visits a website, a cartID is generated, a random 32-bit string is generated, and then the string is put into the cookie, and set the Expiration Time, and the content of the shopping cart is stored in the database, that is, there is an independent table, the php shopping cart deletes expired items
Now we have made a small commodity system to make the shopping cart.
The shopping cart process is clear.
I did this:
When a visitor visits a website, a cartID is generated, which is a random 32-bit string. then, the string is placed in the cookie and the expiration time is set.
The content of the shopping cart is stored in the database, that is, there is an independent table, table_cart

Add a new item to the shopping cart. First, check whether the user has logged on. if the user has logged on, use user_id. if the user has not logged on, use cartID. these are all handled.

If you log on to a user, the items in the shopping cart are permanently retained. of course, you can also delete the items based on the following conditions: if you do not log on within one month, you can delete them.

Now the question is: how can I delete items that are not logged in to the shopping cart?

My idea was to add a field to table_cart, give it a time, and then delete it by time. Is there a better way?

I didn't use session. please give me a better idea. Thank you!

------ Solution --------------------
Is it possible to set the expiration time for a cookie? it will be automatically deleted once the cookie is valid.
------ Solution --------------------
If you have not logged on to the user's shopping cart, put the cookie in it and serialize it first. Then, set the expiration time of setcookie.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.