ASP to make online number of statistics examples _asp Foundation

Source: Internet
Author: User
Tags servervariables
Let's start with a new Access database

Content is

Table Name: Zai

Word Field

1.ip

2.time

Create a file for index.asp

And then on the following program!

<%
'===================================================================================================
'
' ******************** Ice Ling online headcount statistics program V2.0 ******************************
'
' This site program by the "Ice Ling Studio"-Ice cream swordsman Independent production! Please respect the fruits of my labor
'
"Ice Ling Studio" ─━╃→ with strength to create personality
'
' * Author: ice Cream Swordsman
' * Website: http://www.blbcn.com
' * e-mail: bingqilinjianke@163.com
' * qq:68156987
' * Address: Wuxi, Jiangsu
'******************************************************************************
'
' All rights reserved, plagiarism and misappropriation
'
'===================================================================================================


'---------Define Variables
Dim rs
Dim ip
Dim timeout
Dim x
Dim conn
Dim DBPath
'---------define variable end

'---------suggest database links
Set Conn=server.createobject ("Adodb.connection")
DBPath = Server.MapPath ("Zai.mdb")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & DBPath
'---------Create a database link complete

'---------New Database Rs Object
Set rs = Server.CreateObject ("Adodb.recordset")
'---------Build Database Rs Object complete

'---------read client IP address
ip = Request.ServerVariables ("http_x_forwarded_for") ' If the other side is using a proxy server to surf the internet, use Request.ServerVariables ("Http_x_ Forwarded_for ") can get the real IP of each other, if the other side is not through the proxy server Internet, then the value of the IP is null
If IP = "" Then IP = Request.ServerVariables ("remote_addr") ' If the value of IP is null, get his local client address
'---------IP Read complete

'---------read the number of new content added in the database for nearly 20 minutes, and the Group by ip-table IP values are the same as 1
sql= "Select IP from Zai where time >= dateadd (' n ', -20,now ()) Group by IP"
Rs. Open sql,conn,1,1
Zai=rs. RecordCount
Rs. Close
'---------get the number of people online

'---------See if the same value already exists in the database, no x= "yes" and then x= "No"
sql= "Select IP from Zai where ip= '" & IP & "'"
Rs. Open sql,conn,1,1
If rs.eof and Rs.bof then
x= "Yes"
Else
x= "No"
End If
Rs.close
'--------judgment is complete.

'--------Add a new value if there are no identical values in the database
If x= "yes" then ' if there is no IP then add a record
Sql= "SELECT top 1 * zai"
Rs. Open sql,conn,1,3
Rs. AddNew
RS ("IP") =ip
RS ("Time") =now ()
Rs.update
Rs.close
Else ' If there is this IP then the time is changed to the present time

Sql= "SELECT * from Zai where ip= '" & IP & "'"
Rs. Open sql,conn,1,3
RS ("Time") =now ()
Rs.update
Rs.close
End If
'--------judgment joined the conclusion

'--------Delete the value that was added 20 minutes ago
Timeout = DateAdd ("n", -20, Now ())
sql= "Delete * Zai where time < #" & timeout & "#"
Conn. Execute SQL
'--------Delete complete

'--------Close the data object
Set rs=nothing
Conn. Close
Set conn=nothing
%>
document.write ("Total <%=zai%> people online")

ok!

It's done!

Related Article

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.