The only problem is if you hit refresh it'll add it again. Not sure the best way to get around this?
Removing items and changing quantities will work fine on refresh, as duplicating those actions would be inconsequential.
I caution you very strongly against what will essentially be a client side redirect. Not only do they look rather unprofessional, they are an accessibility nightmare.
A more recently popular solution is some kind of state identification sent alongside the addition. When you generate the addition form, try setting a hidden variable equal to a md5 digest of current cart contents. When it is submitted, first calculate that md5 digest again, and only if it matches the value in the hidden field do you permit the addition.
against what will essentially be a client side redirect
I'm inclined to agree with you. After looking into it, the choice is either javascript which you can't rely on, meta refresh which only works after the page loads, or a 302 redirect which is better but as I found you can't set a cookie at the same time.
(I set a cookie for the session ID first time an item is added)
If you use POST for your addition action
I always use GET if I can. POST would be ok, but extremely annoyingly (in IE anyway) if you hit cancel, it doesn't give you the same page back, it displays a 'Web page expired message'. So you either have to hit back until you get to the last non-form page, or renavigate to the site.
What about this: a sequence number stored alongside the session ID in the database. When the basket page loads to add the new item, it must check the sequence number it's given is larger than the one in the database. Assuming it is, add the item and update the sequence number?
Seems a bit more long winded than I'd hoped but can't think of anything better.
When the basket adds an item, there's a 'lock' which can be a cookie or in the database. Each product page removes the lock, so you can't add another item until you've actually navigated off the basket page.
Works perfectly......
.....until they told me they wanted a quick 'type your product code here to add an item' box on the basket page! Item wouldn't add because the lock was still on. I had to change this to the sequence method above. A bit more faffy but it works.
Thanks for suggestions.