Hi
We want to display products a customer has looked at - perhaps just the last 10 or 20.
We did try this via a database, but the storage shot up, and I've seen it on web sites where if you delete cookies, it's gone.
So how do you store up to 10 product ids, in cookies?
How do you store 'recently seen' in Cookies?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do you store 'recently seen' in Cookies?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you store 'recently seen' in Cookies?
I would use a database. To keep the table small, periodically delete entries older than a certain date. If you do use cookies, the PHP manual suggests using explode(). You could also use http_build_query()/parse_str() or json_encode()/json_decode().
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you store 'recently seen' in Cookies?
Well I have created the db and php scripts to delete old and only had new - so it never goes over 20 entries. IT does work.
But wondered if cookies was a better way of going? The DB Method uses their IP to store them. So you could end up having entries that will never be deleted, unless manually deleting.
But wondered if cookies was a better way of going? The DB Method uses their IP to store them. So you could end up having entries that will never be deleted, unless manually deleting.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you store 'recently seen' in Cookies?
You could assign them a "logged out user" id and store that in the table instead of IP address. Set that id as a cookie.
With cookies, one drawback is that every HTTP request the browser sends the cookie data to the server and the server sends it back. Even static files like js, css, and images.
With cookies, one drawback is that every HTTP request the browser sends the cookie data to the server and the server sends it back. Even static files like js, css, and images.