Skip to main content
Inspiring
January 26, 2011
Answered

shopping cart - prevent same session ref being re-used after an order ?

  • January 26, 2011
  • 2 replies
  • 1191 views

Whenever a user enters site and new session is created, along with a unique session ref (uuid).

Various housekeeping is performed when the session expires

BUT, how do I prevent a user who's just ordered, from returning to the site and re-using the same session ref ?

What's the best solution ? Can I prematurely expire the session, or perhaps start a new one and attach this user to it ?

This topic has been closed for replies.
Correct answer Owainnorth

Out of interest, why is it a problem if they *do*?

Seems a little odd to need to manually end a session, so maybe you're looking in the wrong place for a solution, tis all.

2 replies

BKBK
Community Expert
January 27, 2011

Dax Trajero wrote:

... how do I prevent a user who's just ordered, from returning to the site and re-using the same session ref ?

Deny a returning paying(!) customer his session? Yours might be the only shop in town doing that.

If your session housekeeping is any good, then the session variables  pertaining to shopping-cart, payment and delivery would have been  cleared or re-initialized. Often, starting a new session means logging in again. There are a number of reasons why that can be undesirable.

I did an e-commerce course for a year, and learned some strange things. It is in fact to your advantage that a returning customer should keep his session, even after ordering.

For example, it is well known that the chances of a returning customer placing a new order is much higher when he is already logged in than when he has to log in afresh. You could test that hypothesis yourself. Psychologists have also found that e-shoppers often return to the shop to gloat at the goodies they've just ordered. You wouldn't want to deny them their gloating session, would you?

Inspiring
January 28, 2011

Hi, thanks for the input.

If you check Owain's response, he's already said much of the same.

BKBK
Community Expert
January 29, 2011

Dax Trajero wrote:

If you check Owain's response, he's already said much of the same.

Please see the last paragraph as my input, not so much the technical stuff. In my experience, what I would call second-thought orders could contribute significantly to your sales.

Owainnorth
OwainnorthCorrect answer
Inspiring
January 26, 2011

Out of interest, why is it a problem if they *do*?

Seems a little odd to need to manually end a session, so maybe you're looking in the wrong place for a solution, tis all.

Inspiring
January 26, 2011

Why ? I think I panicked when I read an article about a guy who assumed re-using the existing session would contaminate his session code.

I suppose if you perform the appropriate housekeeping once a user has ordered, then there's no reason to re-use the same session ref, assuming they wanted to order again straight away (perhaps they'd forgotten something)

Looking at my code, the orders table (and ordered_items table)  has no link at all to the shopping cart table, so it's not an issue.

Incidentally Owain, do you think it preferrable to use a RAM based shopping cart (opposed to table based) ? I think I want to make that my next project, choosing a suitable data structure to hold the cart in RAM.

Owainnorth
Inspiring
January 26, 2011

We force clients to log in or create an account at the point they first add something to their cart, which means all shopping cart data can be stored in the database indefinitely. It also means the site is easy scalable and can be load-balanced, which RAM-based storage rules out.

No-one has ever complained about having to log in, but many have been impressed to find things still in their cart when they come back to it.

As they navigate around the site and add things to their basket we add these into the tables - their Checkout view is then just selecting from the shopping cart table.

Once a user pays and clicks the complete button we tidy up the shopping cart tables and create an order. By the time the success page returns to their browser all their shopping cart data has been cleared, so there's no way they can do anything wrong or "re-send" the order if it's done properly.

Personally I wouldn't worry about it, concentrate more on making sure someone can't submit an order twice