Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sessions vs cookies for ecommerce cart in php

26 views
Skip to first unread message

johnb...@gmail.com

unread,
Aug 3, 2019, 3:34:46 AM8/3/19
to


I have an ecommerce shop online using php, sql, javascript,ajax and sessions.

I have both guest and members cart options at checkout.

Everything works fine.

I store my cart items in a session currently.

Users can log in or have a guest cart.

Guests cart userids are referenced by the current session id.

members can login and their carts are referenced by their usersids from the database.

The problem is, the session expires after a certain amount of time and so the cart items are lost and the user has to start again.

On doing some research I have found that after the user logs in, I can store his user id in a cookie and I can specify how long that cookie lasts for which is ideal!

I am thinking of changing the code so that I store the items added to the cart in my database tables and simply reference them with the user id ive stored in his cookie.

That way He can shop for ages and not lose his cart and I can send abandon cart emails etc...

I think this would work well as nearly every website uses cookies so people have to have them enabled in their browser these days. I could show a warning message if cookies arent enabled anyway..

What does everyone think about this?

Please note I am not seeking security advice here.

I havent implemented this as yet - Im really looking to see if I can set my session lifetime to last a few hours/days instead.

J.O. Aho

unread,
Aug 17, 2019, 5:52:26 PM8/17/19
to
On 03/08/2019 09.34, johnb...@gmail.com wrote:

> I havent implemented this as yet - Im really looking to see if I can set my session lifetime to last a few hours/days instead.

The life length of a cookie/sessions (a session is a cookie too) is in
the end decided by the client, for example there are browsers who will
remove all cookies/sessions as soon as the user leaves the site.


--

//Aho
0 new messages