Page 1 of 1
How do you store 'recently seen' in Cookies?
Posted: Fri Apr 13, 2012 7:23 am
by simonmlewis
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?
Re: How do you store 'recently seen' in Cookies?
Posted: Fri Apr 13, 2012 2:04 pm
by tr0gd0rr
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().
Re: How do you store 'recently seen' in Cookies?
Posted: Fri Apr 13, 2012 2:08 pm
by simonmlewis
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.
Re: How do you store 'recently seen' in Cookies?
Posted: Fri Apr 13, 2012 2:24 pm
by tr0gd0rr
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.