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.

Inspiring
January 26, 2011

There's no one simple thing that needs doing, it's a multi-pronged (shudder) approach for want of a better sickening management phrase.

First up, when they click the Complete Order button, use Javascript to stop them clicking it agan. In the CF page that gets posted to, the *first* thing at the top of the page needs to be to check for the existance of a variable called  session.OrderSentForCompletion or similar, and make sure it's not true. If it *is*, they've gone back and re-submitted and the page should error or whatever you choose to do.

If it hasn't been set, do so, eg:  session.OrderSentForCompletion = true

Then send the request to the provider, get the data back and clear the session scope.

That way even if the CFM page is posted to twice, the first marks the flag to say it's been run, so the second won't then process it again. Apologies for the awful explanation but the girlfriend is watching "16 and Pregnant", and it's pretty distracting. Hopefully you get the rough idea anyway...

O.


Yeah, totally get it, thanks.

Good tip about the table version of a shopping cart allowing you to leverage additional servers to cope with demand. If I had gone down the RAM based cart route, it wouldn't have done so.

Thanks again Owain