Recommended: Detailed explanation of Asp functions Cbool(string) Convert to Boolean value Cbyte(string) Convert to byte type value Ccur(string) Convert to currency type value Cdate(string) Convert to day-ahead type value Cdbl(string) Convert to double precision value Cint(string ) Convert to an integer value Clng(string) Convert to a long integer value Csng(string) Convert to a single precision value Cstr(
ASP objects, there are 5 objects in ASP: Request, Response, Session, Application, Server. The following only describes the object attributes that can be used in this article. For other attributes, please refer to relevant materials. The principle of the method provided in this article is: set a logical variable IsVoted, and verify the value of IsVoted before voting. Only when the value is False can you vote, otherwise it will be considered that the vote has been cast.The Application object is an object that handles information shared by all users in a specific ASP application. That is to say, the Application object is an object shared by all web pages on all networked machines. Variables defined and set by the Application object are accessible to all web pages for all users. You can use the Application object to define variables and change the value of variables. The syntax format is as follows: Application (variable name) = expression. It can be referenced through Application (variable name) in the .asp file. Application saves the value of the variable on the WebServer side.
The Session object is used to manage information for a single user, and Session variables are only called between pages (that is, within a Session). Session variables are private, and changes to the value of a variable in one Session do not affect the value of the variable of the same name in another Session. The Session object also saves variable values on the server side, but the locations where each Session is saved are different. Because Session is private, there are as many IsVoted variables as there are Session objects, and there is no relationship between these variables.
The Cookies object cannot exist alone. It is attached to the Request and Response objects. When using it, Request or Response must be added before Cookies. Like Application and Session, Cookies can also save the value of variables, but Cookies only save the value of variables on the browser client. Variables defined with Cookies have an attribute: the usage period of Cookies variables can be set, and once the usage period is set, Cookies variables can be shared by all users logged in from the same machine. We can use this attribute of Cookies to set the interval. There will be a certain amount of time before you can vote again.
The Server object mainly completes some work that needs to be processed by the WWW server. In this article, we mainly use Request.ServerVariables to read the client's IP address in the Server's environment variable, and set how long it will take for the same IP address to vote again based on the IP address.
The Global.asa file completes the definition and initialization tasks of shared variables and files. The Global.asa file must be located in the root directory of the ASP application. An ASP application can only have one Global.asa file. Global.asa contains four events: Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd. We define and initialize Application variables and Session variables in the Application_OnStart and Session_OnStart events, so that these variables can be read in future web pages. ASP reads the contents of Global.asa under the following circumstances:
1. After the WebServer is started, the first request is made to call any .asp file in the ASP application;
2. Users who are not in the Session state request to call the .asp file of the ASP application.
Method 1: Using Session object
Set the logical variable IsVoted in the Session_OnStart event of Global.asa. The initial value is FALSE (indicating that no vote has been taken yet). After voting, change the value of IsVoted to TRUE in the .asp program (indicating that a vote has been taken). The value of IsVoted must be determined before each vote. If the value of IsVoted is TRUE, you can no longer vote; if the value is FALSE, you can vote.
Because the use of the Session object must be coordinated with the browser's Cookies function, before judging the IsVoted value, you must first determine whether the browser's Cookies function is turned on. If it is closed, this method will be invalid, so in this case, a prompt message must be given and the Response.End command must be used to interrupt the execution of the .asp program to prevent repeated voting. The process is shown in Figure 1:
Among them, the function to determine whether Cookies is turned on is relatively complicated. The function implementation code (VBScript) is now given.
Share: Analyze the code for connecting various databases using ADO Let’s briefly introduce several ADO connection methods: ODBCDSN, ODBCDSN-Less, OLEDBProvider, and MSRemoteProvider. 1. ODBCDSN connects to I.DSN oConn.OpenDSN=AdvWorks;_ UID=Admin;_ PWD=; Note: Starting from MDAC2.1, you can no longer use this method, that is, just put the DSN file name in ConnectString
Total 3 pages Previous page 123 Next page