Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z - Internet FAQ Archives

FAQ: Frequently Asked Questions about CGI Programming
Section - 3.19 How can I avoid users hitting "submit" twice?

( Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Business Photos and Profiles ]

Top Document: FAQ: Frequently Asked Questions about CGI Programming
Previous Document: 3.18 How can I use Caches to make CGI scripts faster and more Net-friendly?
Next Document: 3.20 How can I stop my CGI script reading and writing files as "nobody"?
See reader questions & answers on this topic! - Help others by sharing your knowledge

You can't.   You just have to deal with it when they do.

You can avoid re-processing a submission by embedding a unique ID in your
Form each time it is displayed.   When you process the form, you enter
the ID in a database.  Or, if it's already there, you don't repeat the

You probably want to expire your database entries after a little time:
an hour should be fine in a typical situation.

If you're already using cookies (e.g. a shoppingcart), an alternative is
to use the cookie as a unique identifier.   This means you also have to
handle the situation where a user deliberately "goes round twice" and
submits the same form with different contents.

If your script may take some time to process, you should also consider
running it as a background job, and returning an immediate
acknowledgement to the user (see above if your "immediate" response
gets delayed until processing is complete in any case).

User Contributions:

Comment about this article, ask questions, or add new information about this topic: