Recommended: ASP multiple query solution We often encounter multiple query problems, and long SQL statements often make monks confused. Especially when the client part fills in query conditions, it will be even more difficult to use ordinary methods. The following cleverly uses the identity of where 1=1 (in fact, it's a lot, just let it have a value of TRUE) to solve this problem. Text summary 'subject information title'com
How to limit multiple repeated submissions of forms in ASP? On the Internet, we encounter countless forms every day, and we also see that most of them do not restrict users from submitting the same form multiple times. The lack of such restrictions can sometimes produce some unexpected results, such as duplicate subscription to email services or duplicate voting.
This article describes a simple way to prevent users from submitting the same form multiple times during the current session in an ASP application. It mainly consists of four subroutines. In simpler applications, you just need to place these codes in the include file and directly quote them; for those more complex environments, we will give some improvement suggestions at the end of the article.
1. Basic work process
Next, we discuss these four subroutines in turn.
(ASP restricts multiple repeated submissions of forms) Initialization
Here we want to save two variables in the Session object, among which:
⑴ Each form corresponds to a unique identifier called FID, and a counter is used to make this value unique.
⑵ Whenever a form is successfully submitted, its FID must be stored in a Dictionary object.
We use a dedicated process to initialize the above data. Although each subroutine will call it in the future, it will actually only be executed once during each session:
The following is the quoted content: Sub InitializeFID() If Not IsObject(Session(FIDList)) Then Set Session(FIDList)=Server.CreateObject(Scripting.Dictionary) Session(FID)=0 End If End Sub |
(Restrict multiple repeated submissions of forms in ASP) Unique identifier for generating forms
The following function GenerateFID() is used to generate a unique flag for the form. The function first adds the FID value by 1 and then returns it:
The following is the quoted content: Function GenerateFID() InitializeFID Session(FID) = Session(FID) 1 GenerateFID = Session(FID) End Function |
(Multiple repeated submissions of restricted forms in ASP) Register the submitted form
When the form is submitted successfully, its unique identifier is registered in the Dictionary object:
The following is the quoted content: Sub RegisterFID() Dim strFID InitializeFID strFID = Request(FID) Session(FIDlist).Add strFID, now() End Sub |
(ASP restricts multiple repeated submissions of forms 4) Check whether the form is submitted repeatedly
Before formally processing a form submitted by the user, you should check whether its FID is registered in the Dictionary object. The following CheckFID() function is used to complete this work. If it has been registered, it returns FALSE, otherwise it returns TRUE:
The following is the quoted content: Function CheckFID() Dim strFID InitializeFID strFID = Request(FID) CheckFID = not Session(FIDlist).Exists(strFID) End Function |
2. How to use
There are two places where the above functions are used, namely when form generation and result processing. Assuming that the above four subroutines have been put into the inclusion file Forms.inc, the following code decides whether to generate a form or process the form results based on the FID value. The processing process it describes is suitable for most ASP applications:
The following is the quoted content: < %Option Explicit%> < !--#include file=forms.inc <HTML> < HEAD> < TITLE>Form Submission Test</TITLE> < /HEAD < BODY> < % If Request(FID) = Then GenerateForm Else ProcessForm End If %> < /BODY> < /HTML> |
GenerateForm is responsible for generating the form, and the form should contain a hidden FID, such as:
The following is the quoted content: < % Sub GenerateForm() %> < form action=< %=Request.ServerVariables(PATH_INFO)%> method=GET> < input type=hidden name=FID value=< %=GenerateFID()%>> < input type=text name=param1 value=> < input type=submit value=OK> < /form> < % End Sub %> |
ProcessForm is responsible for processing content submitted through the form, but before processing, it should first call CheckFID() to check whether the current form has been submitted. The code class is such as:
The following is the quoted content: < % Sub ProcessForm() If CheckFID() Then Response.Write What you type is |
Share: How to generate html in ASP? There are already many news systems that generate html, but they all use templates. This function saves the html code generated by the asp page into an html file, so there is no need to change the original page to easily complete a news system that generates html. ^_^ Since the code is relatively short, the following quoted content is not commented here: % 'When the target