Limit the same form being submitted
On the Internet, we will encounter countless forms every day, and most of them have not restricted users to submit the same form multiple times. Lack of this limitation sometimes generates some expected results, such as repeated subscription mail services or repeated votes.
This article describes a simple way to prevent users from submitting the same form multiple times during the current session in ASP applications. It is mainly composed of four subroutines, in a simpler application, you only put these code directly in the included file; for those more complex environments, we will give some improvements in the article.
First, the basic work process
Here we discuss these four subprograms in turn.
(1) initialization
Here we have to save two variables in the Session object, where:
(1) Each form corresponds to a unique identifier called FID, in order to make this value to use a counter.
(2) Whenever a form is successfully submitted, it must store its FID in a Dictionary object.
We use a dedicated process to initialize the above data. Although each subroutine will call it, it actually executes only once during each session:
Sub initializefid () if not isobject (SESSION ("FIDLIST") = Server.createObject ("scripting.dictionary") Session ("fid" = 0 end if End Sub
(2) Generating a unique identifier of a form
The following function generateFID () is used to generate a unique logo of the form. This function first adds the FID value 1 and then returns it:
Function GenerateFid () Initializefid Session ("FID") = session ("fid") 1 generatefid = session ("fid") End Function
(3) Registration has submitted a form
When the form is successfully submitted, register its unique identifier in the Dictionary object:
Sub registerfid () DIM STRFID INITIALIZEFID STRFID = Request ("fid") session ("fidlist"). Add strfiD, now () end SUB
(4) Check if the form is repeated
Before formally handling the form submitted, you should check if its FID has been registered in the Dictionary object. The following checkfid () function is used to complete this work, if it is already registered, it returns false, otherwise returns true:
Function checkfid () DIM STRFID INITIALIZEFID STRFID = Request ("FID") checkfid = not session ("fidlist"). Ends (strfid) end function
Second, how to use
There are two places to use the above functions, that is, when the form is generated, when processing is generated. Suppose the above four subroutines have been placed in the included files fors.inc, the following code determines the generation form or the processing form, which is suitable for most ASP applications based on the FID value.
<% OPTION Explicit%>
<% SUB generateform ()%>