Another method of online population statistics (1 application only)

Source: Internet
Author: User
application| Statistics | online | The most common method is to use session, but the disadvantage is that there is no immediate response online (with timeout) and server resources (if there are 100 people online there are 100 sessions, think about 8) Last time (seems to be a long time) introduced a method of using application+cookies, but the implementation of some cumbersome and also to set a hidden from the Refresh page.
This method avoids the above malady, after practice, the effect is good (example: WWW. Atersoft. Com/bbs), as follows:
Assume index. HTM is a frames page that contains three frames for Id=left,id=top and Id=bottom
1, make a statistic page usernum. Asp
<p> Statistical data ... </p>
<%
User=request.querystring ("User")
If User=0 then ' if left the number of people-1
Application.Lock
Application ("num") =application ("num")-1
Application.UnLock
Response.Write "<script>self.close ();</script>"
ElseIf User=1 Then ' if entered then +1
Application.Lock
Application ("num") =application ("num") +1
Application.UnLock
End If
%>

2, in the Frame page as (INDEX. HTM) embedded Usernum. Asp
<body onbeforeunload= "window.open (' usernum.asp?user=0 ', ' num ', ' menubar=no ')" >
......
<iframe src= "usernum.asp?user=1" frameborder=0 width=0 height=0></iframe>
3, in the need to display the number of pages (assuming the left display) to add
<div id=num><%=application ("num")%></div>
4, set the need to update the data page (such as bottom)
Function TJ () {
Top.left.num.innerhtml=<%=application ("num")%>;
}
<body onload= "TJ ()" >
Over, this is just an example, the specific application can be flexible, in addition, why when leaving window. OPEN Usernum. Where's the ASP? Because if the same is put in ifrme, the window closes too fast, usernum. ASP page can be turned off when it is too late to reduce the number of people, deficiencies welcome to explore GWLX@21CN.COM



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.