Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Back button - ensuring order are not submitted twice (PHP)
Ensuring that forms aren't "double submitted" is critically important on certain automated data entry applications - the classic example being an absolute need NOT to allow your user to place an order twice if he / she uses the "back" button and presses submit again.

I came across an article on a Java forum talking about redirect after Post, but I can't say that I'm thrilled. An over-complex solution and there's much easier ways of doing it in PHP (and in Java and other languages too!).

Almost inevitably, on line ordering systems are going to comprise a number of pages where you select your product(s) and then, as a final operation, confirm your order.

In PHP, you should use the $_SESSION superglobal to maintain the state of each individual user as he / she goes through your site, starting each operation that updates the embryonic order with a call to session_start. By default, values WILL be stored between pages in this super-global and the back button will leave the order-in-progress (a.k.a. the shopping cart) in tact - and that's ideal because you'll not want your customers to loose their selected products if they commit the 'crime' of doing a back.

But when one of your users selects the "yes, confirm my order" button or the equivalent, you DO want to prevent a step backwards resurrecting the data. There are two ways of doing this. The easiest is to do a session_destroy which eliminates the content of the shopping cart from the session when it's confirmed - the rest of your submit code for that page will have emailed the order confirmation, added the necessary information to your table of to-be-filled orders, and so on. The alternative way (if you don't want to loose the whole session - perhaps you want to leave your user logged in, for example) is to selectively clear the vital variables such as the cart-to-date form $_SESSION when the order is placed.

We have an example of this approach on our web site - try it out here and see the source code of the main application here. You'll note that this is part of a demonstration of the "four layer model" for major applications (you can write appliactions in PHP that have the beauty of A Picasso, or ones that look like the dog's dinner) - but that's a story for another entry.
(written 2007-04-28 07:55:18)

 
Associated topics are indexed under
H115 - Designing PHP-Based Solutions: Best Practice

Back to
Extended Credit request - train in June and be paid in September
Previous and next
or
Horse's mouth home
Forward to
Leaning tower of Cheeser

Some other Articles
Smoking, or no? The law insists we spell out the obvious
Emailing as HTML (Web Page) - PHP example
Moving out some of the web site bloat
Leaning tower of Cheeser
Back button - ensuring order are not submitted twice (PHP)
Extended Credit request - train in June and be paid in September
Grand Central Station
A better alternative to cutting and pasting code
Cheddleton, Staffordshire
A contrast in room rates and facilities
1635 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho