Let’s first create a new ACCESS database
The content is
Table name: zai
The fields are
1.ip
2.time
Create a file as index.asp
Then follow the procedure below!
<%
'================================================== ==================================================
'
'************************ Bingling Online People Counting Program V2.0 ******************** **********
'
'The program of this website is independently produced by "Bingling Studio" - Ice Cream Swordsman! Please respect the fruits of your labor
'
' "Bingling Studio"─━╃→Create personality with strength
'
'* Author: Ice Cream Swordsman
'* Website: http://www.blbcn.com
'* Email: [email protected]
'* QQ:68156987
'* Address: Wuxi, Jiangsu
'************************************************ *******************************
'
'Copyright·Plagiarism and misappropriation will be investigated
'
'================================================== ==================================================
'---------Define variables
dimrs
dimip
dim timeout
dim x
dim conn
dimdbpath
'---------End of defining variables
'---------Suggested database link
set conn=server.createobject(adodb.connection)
DBPath = Server.MapPath(zai.mdb)
conn.Open driver={Microsoft Access Driver (*.mdb)};dbq= & DBPath
'---------Establishing database link completed
'---------Create a new database RS object
set rs = server.createobject(adodb.recordset)
'---------Creating database RS object completed
'---------Read the client IP address
ip = Request.ServerVariables(HTTP_X_FORWARDED_FOR) 'If the other party uses a proxy server to access the Internet, use Request.ServerVariables(HTTP_X_FORWARDED_FOR) to get the other party's real IP. If the other party does not access the Internet through a proxy server, the IP value is empty.
If ip = Then ip = Request.ServerVariables(REMOTE_ADDR) 'If the value of IP is empty, get his local client address
'---------IP reading completed
'---------Read the number of new content added in the database in the past 20 minutes, 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
'---------Check whether there is already the same value in the database, if not, x=yes, if not, 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 completed
'--------If there is no same value in the database, add a new value
if x=yes then' If there is no such IP, add a record
sql=select top 1 * from 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, change the time to the current time
sql=select * from zai where ip=' & ip & '
rs.Open sql,conn,1,3
rs(time)=now()
rs.update
rs.close
end if
'--------Judge that joining is complete
'--------Delete the value added 20 minutes ago
timeout = dateadd(n, -20, now())
sql=delete * from zai where time < # & timeout & #
conn.Execute sql
'--------Deletion completed
'--------Close the data object
set rs=nothing
conn.Close
set conn=nothing
%>
document.write(Total <%=zai%> people online)
OK!
Done!