ASP makes an online statistics instance

Source: Internet
Author: User
Tags servervariables

Create an Access database first.

Content is

Table Name: zai

The field is

1. IP

2. Time

Create a file named index. asp

Then we will see the following:Program!

<%
'================================================ ========================================================== ================================
'
************ ******************
'
'The program on this site is independently created by "Ice Ling Studio"-ice cream swordsman! Respect your labor achievements
'
'Ice Ling studio '-Yun → build individuality with strength
'
'* Author: Ice Cream swordsman
'* Website: http://www.blbcn.com
'* Email: bingqilinjianke@163.com
'* QQ: 68156987'
'* Address: Wuxi, Jiangsu Province
'*************************************** ***************************************
'
'The copyright ownership-the misappropriation of plagiarism is required
'
'================================================ ========================================================== ================================

'--------- Define variables
Dim rs
Dim IP
Dim timeout
Dim X
Dim Conn
Dim dbpath
'--------- Define variable end

'--------- Suggested database connection
Set conn = server. Createobject ("ADODB. Connection ")
Dbpath = server. mappath ("Zai. mdb ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & dbpath
'--------- Database connection established

'--------- Create a database Rs object
Set rs = server. Createobject ("ADODB. recordset ")
'--------- Database Rs object created

'--------- Read 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") can obtain the real IP address of the other party. If the other party does not access the Internet through the proxy server, the IP address value is blank.
If IP = "" Then IP = request. servervariables ("remote_addr") 'If the IP value is null, obtain its local client address.
'--------- IP address read is complete

'--------- Read the number of new content added to the database in the last 20 minutes. Group by IP-the same table IP value is recorded 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 online person value

'--------- Check whether the database has the same value. If not, x = "yes" indicates that 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 complete

'-------- Add a new value if the database does not have the same value
If X = "yes" then', add a record if this IP address does not exist.
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 this IP address exists, 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
'-------- Check that join is complete

'-------- Delete the value added 20 minutes ago
Timeout = dateadd ("N",-20, now ())
SQL = "delete * From Zai where time <#" & timeout &"#"
Conn. Execute SQL
'-------- Deleted

'-------- Close the Data Object
Set rs = nothing
Conn. Close
Set conn = nothing
%>
Document. Write ("Total <% = Zai %> online users ")

OK!

Finished!

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.