Class Online
Sub UserState (ustate)
Dim userip,xmldoc,root,newuser,delnode,otime
Otime=day (now ()) *24*60+hour (now ()) *60+minute (now ())
Set xmldoc = Server.CreateObject ("Msxml2.domdocument")
Xmldoc.async = False
Xmldoc.load (Server.MapPath (XmlUrl & "Online.xml"))
Set Root=xmldoc.selectnodes ("//online/at[@oSessionID = '" & Session.SessionID & "' or @oUname = '" & Mycname & "' or ouip= '" & Userip & "']"
If Root.length=0 Then
Set Newuser=xmldoc.createelement ("at")
XmlDoc.documentElement.appendChild (NewUser)
Newuser.setattribute "Osessionid", Session.SessionID
Newuser.setattribute "Ouname", Mycname
Newuser.setattribute "Outype", Myutype
Newuser.setattribute "Oustate", ustate
Newuser.setattribute "Ouip", Userip
Newuser.setattribute "Ouactivetime", Otime
Set newuser=nothing
Else
Root.item (0). Attributes.item (0). Value=session.sessionid
Root.item (0). Attributes.item (1). Value=mycname
Root.item (0). Attributes.item (2). Value=myutype
Root.item (0). Attributes.item (3). value=ustate
Root.item (0). Attributes.item (4). Value=userip
Root.item (0). Attributes.item (5). Value=now ()
End If
Set Delnode=xmldoc.documentelement.selectsinglenode ("//online/at[@oUactiveTime <" "& Otime + &" '] ")
Root.reomvechild (Delnode)
Set delnode=nothing
Set root=nothing
Xmldoc.save (Server.MapPath (XmlUrl & "Online.xml"))
End Sub
Sub Onlinecount ()
Dim Uonline,gonline,root,xmldoc
Set xmldoc = Server.CreateObject ("Msxml2.domdocument")
Xmldoc.async = False
Xmldoc.load (Server.MapPath (XmlUrl & "Online.xml"))
Set Root=xmldoc.selectnodes ("//online/at[@oUtype = ' 1 ']")
Uonline=root.length
Set Root=xmldoc.selectnodes ("//online/at[@oUtype = ' 0 ']")
Gonline=root.length
Set root=nothing
Set xmldoc=nothing
Response.Write "Online:" & Gonline+uonline & "Member:" & Uonline & "Visitors:" & Gonline
End Sub
function Xchar (str)
Xchar=str
Xchar=replace (Xchar, "" "", "" ")
Xchar=replace (Xchar, "" "", "")
Xchar=replace (Xchar, "<", "<")
Xchar=replace (Xchar, ">", ">")
Xchar=replace (Xchar, "&", "&")
End Function
End Class
Although this code is simple but has been covered with xmldom creation, save, node additions, deletions, node property settings, Dom using XSL for simple queries, and so on.
In the online number of more sites, it is recommended to use XSL index, otherwise the speed is unimaginable.
In this paper, Otime record the user's last activity time, because the date of the XML data processing is more complex, such as to use dtd,xsl and so on to code writing and user use caused the same, so here it converts it to digital type.
The online statistics are taken by the length of the selected document, but you can also use the XSL count function directly.
Xchar is an XML special character processing function, which is not prefixed with character processing and is used when used in character-type data processing. Of course, if you are very familiar with DTDs and so on, you can use this function to control the document.