Ways to prevent repeated voting on the Web (i)

Source: Internet
Author: User
Tags exit variables servervariables time interval client root directory
Polling | Repeated online surveys are an effective way to collect information quickly, but there is a shortage of online surveys in some websites, that is, any user can repeatedly vote according to their hobbies. Because all the survey results are for reference to decision-making, whether for a unit or a department, decision-making errors will bring unexpected losses, so to prevent repeated voting is of great significance. Several methods based on ASP (Active Server Page) presented in this paper can prevent repeated voting in a certain extent.

ASP objects
There are 5 objects in the asp: Request, Response, Session, application, Server. The following only for the purposes of this article can be used to explain the object properties, other aspects of the properties please refer to the relevant information. The method provided in this article is to set up a logical variable isvoted, to verify the value of isvoted before voting, and to vote only if the value is false, otherwise the vote is considered to have been cast.
The Application object is an object that handles the shared information of all users in a particular ASP application, meaning that the Application object is the object shared by all Web pages on all networked machines. A variable defined and set by the Application object, accessible to all pages of all users. The Application object allows you to define variables and to change the value of the variable, with the following syntax: Application ("variable name") = expression. The. asp file can be referenced by application ("Variable name"). Application saves the value of the variable on the web Server side.

Session objects are used for individual user management information, and session variables are only called between pages (that is, within a session). The session variable is private, and a change in the value of a variable in a session does not affect the value of the variable of the same name in another session. The session object also saves the value of the variable on the server side, but each session is saved in a different location. Because the session is private, there are many isvoted variables in the number of Session objects, and there is no relationship between these variables.

A cookie object cannot exist alone, it is attached to the request and response object and must be added to the request or response before the cookie in use. Like application and session, cookies can also hold variable values, but cookies only store the values of variables on the browser client. The variables defined with cookies have a property: You can set the duration of the cookie variable, and once the usage period is set, the cookie variable can be shared by all users who are logged on from the same machine. We can use this property of cookies to set a certain time interval before voting again.

The server object primarily accomplishes some work that requires WWW server processing, In this article, we mainly use Request.ServerVariables to read the IP address of the client in the environment variable of the server, and to set the same IP address according to the IP address to be able to vote again.

The Global.asa file completes the definition and initialization tasks for shared variables and files. The Global.asa file must be located in the root directory of the ASP application, and an ASP application can have only one global.asa file. Global.asa contains Application_OnStart, Application_OnEnd, Session_OnStart, Session_OnEnd four events, we in Application_OnStart, The Session_OnStart event defines the application variable and the session variable and initializes it so that the variables can be read in a later Web page. The ASP reads the Global.asa content in the following situations:

1. The first request to invoke any. asp file in the ASP application after the Web server is started;

2. Users who are not in session state request to invoke the. asp file applied by ASP.

Method one: Using the Session object
Set the logical variable isvoted in the Global.asa Session_OnStart event, with the initial value false (indicating that there is no vote), and then change the isvoted value to True (indicating that the ticket has been voted) in the. asp program. Judge the value of isvoted before each vote. If the value of isvoted is true, you cannot vote again, or you can vote if the value is false.
Because the session object must be used in conjunction with the browser's cookie function, you must first determine whether the browser's cookies are turned on before judging the isvoted value. If it is off, the method fails, so in this case the prompt must be given and the Response.End command interrupted. Implementation of the ASP program to prevent repeated polling. The process is shown in Figure 1:




The function to judge whether a cookie is open is more complex, and the function implementation code (VBSCRIPT) is given.

<%
Function Iscookiesopen ()
Dim ClientIP, URL, QueryString, IsNew

Application.Lock
If session ("SessionID") =session.sessionid Then
Iscookiesopen = True
Clearapp
Exit Function
End If

IsNew = False
If session ("SessionID") = Empty Then
Currentip =request.servervariables
("REMOTE_ADDR")
If currentip <> Application ("IP") Then
Clearapp
IsNew = True
End If
End If
If not IsNew and application ("Visit") >= 1 Then
Iscookiesopen = False
Clearapp
Exit Function
End If
Application ("Visit") = Application ("Visit") + 1
Application ("IP") =request.servervariables
("REMOTE_ADDR")
Session ("SessionID") = Session.SessionID

URL = "_page_=" &request.servervariables
("Path_info")
Querystring=request.servervariables
("Query_string")
If Len (QueryString) > 0 Then url = URL & "&" & QueryString
If not response.isclientconnected Then Clearapp
End Function

Sub Clearapp ()
Application ("Visit") = 0
Application ("IP") = ""
End Sub
% >

Use the Iscookiesopen () function directly in the. asp file to determine if the cookie is open.

Vulnerability to this approach: if you open a new browser window again, you will still be able to vote in the newly opened browser window. This is because the session is private, and the change of a variable in a session does not affect the value of another session's variable of the same name. To solve this problem, method two is given below.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.