Recommended: ASP Example: ASP converts Chinese characters into pinyin functions The pinyin is not comprehensive enough, so it is not recommended to use it. Just learn the method~ The following is the quoted content: <% Set d = CreateObject(Scripting.Dictionary) d.add &quo
When browsing the web page, you can often see that the number of people on the current website is the same as the number of people online. How to make one with ASP? First, let’s analyze its practices. Generally speaking, these online number statistics refer to the number of visitors within a period of time. For example (within 5 minutes, within 10 minutes) and the length of this time is set by the designer.
In this period, you can calculate the total number of visitors to each different IP to get the current number of online users. However, there is an accurate problem here. As for how to use precise statistics, it is different methods for each person. For example, you can use an automatically submitted page, read COOKIES every once in a while, etc. In ASP, there is a better technique, which is to use the session object to count. Here I will introduce the gobal.asa file. This is a very important file. Please take a look at its structure.
| The following is the quoted content: <SCRIPT LANGUAGE=VBScript RUNAT=Server> Sub Session_OnStart End Sub Sub Session_OnEnd End Sub sub Application_OnStard End Sub sub Application_OnEnd End Sub</SCRIPT> |
When a session occurs (the user browses the web page and issues a request to the web server), then, if the first user is the first user after the server is started, the two events of Application_OnStard and Session_OnStart will occur at the same time. After that, if another user sends a request, the Session_OnStart event will only occur. The lifetime of the session can be set. Session.timeout=X (minutes)
OK, with this very useful method, we can accurately count the number of people online, and the total number of people is saved by an application variable. When the first session starts, place a statement to clear the counter in the Application_OnStard event application(online)=0, and then, in the Session_OnStart event, place a statement to increase the number of people online application(online)=application(online) 1, and in the Session_OnEnd event, place a statement to reduce the number of people online accordingly, so that the count value is reduced by one.
In this way, the file will be changed to the following
| The following is the quoted content: <SCRIPT LANGUAGE=VBScript RUNAT=Server> Sub Session_OnStart application(online)=application(online) 1 End Sub Sub Session_OnEnd application(online)=application(online)-1 End Sub sub Application_OnStard application(online)=0 End Sub sub Application_OnEnd application(online)=0 End Sub</SCRIPT> |
Next, write a program that displays graphic numbers and displays the number of people online on the specified page. This will result in the number of people
| The following is the quoted content: *online.asp <% @language=vbscript %> <% tmp=application(online) tmp=Cstr(tmp) dim disp(20) dim images(20) dbbits=len(tmp) for I= 1 to dbbits disp(I)=left(right(tmp,I),I-(I-1)) next for I=dbbits to 1 step -1 images(I)=<img src=&http://xxxx.com.cn/pic&/&disp(I)&.gif> response.write document.write(&images(I)&); next %> |
The above program is very simple, and I won’t analyze it here. Please read it yourself. On the page where the online statistics are called, use a script statement to refer to the online.asp file to display the graph statistician.
| The following is the quoted content: <script language=JavaScript src=http://xxxx.com.cn/online.asp></script> |
Now that's OK, remember the key point, you must place gobal.asa on the correct web application root directory, and it is best to create a new web application for this statistics separately. Don't be confused with other programs, otherwise the resulting data will be inaccurate, and it is also very easy to modify this program to online statistics for multiple users. This will provide online statistics services. Please think about how to implement it again...
Share: Getting started: Common error handling for ASP dynamic web page production ASP error handling ASP is so simple that many developers don’t think about error handling. Error handling can make your application more reasonable. I've seen many commercial websites written in ASP, most of which ignore error handling. The wrong type