Statistical research on online population of ASP forum

Source: Internet
Author: User
Tags datetime servervariables table name
Statistics | online | The number of online people recently made a small forum with ASP, customers asked to count the number of online, so spent a little time to write an online statistical visit member function. Many documents are also viewed in the process of writing. Self-sensory methods can be more accurate statistics on the number of online. Certainly also has the insufficiency place, hoped that each teacher corrects.

Special Note:

This forum login is to use user name login, login to get the user nickname. The entire site does not display the user name, I think relatively safe, so there is a nickname and username difference.

1. Building Database Tables
Table name is online
Set the following fields
Id ' is used to record the Session.SessionID of each visit.
Name ' If it is a visitor, it is recorded as a visitor.
Online ' If is to visit each 0 if it is a member 1
DateTime ' Recent activity Time
Username ' Member's login username, the visitor is empty.
IP ' log access all logon IP

Head.asp ' writes the online number to the database table, which must be searched in each of the ASP pages for browsing.
<%
Set Rs=server.createobject ("ADODB. Recordset ")
If session ("username") = "" Then to determine that the user is not logged in
Sql= "SELECT * from online where id= '" ' &session.sessionid& "'" to determine whether this sessionid exists in the database table.
Rs. Open sql,conn,1,3
If Rs.eof then ' visitors for the first time browsing
Rs.addnew
RS ("id") =session.sessionid
RS ("name") = "Visitor"
RS ("online") =0 ' 0 means that the user is not logged in, is a tourist identity
RS ("datetime") =now ()
Userip = Request.ServerVariables ("Http_x_forwarded_for")
If Userip = "" Then
userip= Request.ServerVariables ("REMOTE_ADDR")
End If
RS ("IP") =userip
Else ' visitors not for the first time browsing
RS ("datetime") =now () Update activity time
Rs.update
Rs.close
End If
Else
Sql= "SELECT * from online where id= '" "& Session.SessionID &" ' or admin= ' "&session (" username ") &" ' "' Judge Sess The Ionid or user name record already exists in the datasheet.
Rs. Open sql,conn,1,3
If Rs.eof Then
Rs.addnew ' Members enter the website for the first time (may login directly from the homepage of the website to enter the forum).
RS ("id") =session.sessionid
RS ("name") =session ("show") ' Write user nickname
RS ("username") =session ("username") ' Write to login user name
RS ("online") =1 ' means that the user has landed, is a member
RS ("datetime") =now () ' Sets the current system time to the user's logon time
Userip = Request.ServerVariables ("Http_x_forwarded_for")
If Userip = "" Then
userip= Request.ServerVariables ("REMOTE_ADDR")
End If
RS ("IP") =userip
else//member is not the first time to browse the site, visitors login site.
RS ("name") =session ("show") updates user nicknames
RS ("username") =session ("username")
RS ("online") =1 ' means that the user has landed, is a member
RS ("datetime") =now ()
End If
Rs.update
Rs.close
End If
Set rs=nothing
%>
Conn.execute ("Delete from online where DateDiff (' s ', Datetime,now ()) >60") ' Delete 60 seconds without active visitors, time can adjust themselves.

Interested and opinions of friends can send letters to qizulovemin@hotmail.com, hope and teachers to exchange learning.



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.