动网:增加用户访问列表



上图为最终的效果,可以很方便的查看每天用户登录的具体时间。

本次修改针对7.1 sp1版,打开login.asp中增加两个函数FormatDate和WriteLogin:
'==========用户访问登记=========
Function FormatDate()
    Dim iYear,iMonth,iDay
    iYear = year(now())
    iMonth = month(now())
    iDay = day(now())
    iMonth = Right("0" & iMonth,2)
    iDay = Right("0" & iDay,2)
    FormatDate = iYear & "-" & iMonth & "-" & iDay
End Function

Function WriteLogin(user)
    Dim xmlPath
    Dim objDom,objRoot,objAtt,objTemp,objTemp2,objTemp3,objTemp4
    
    xmlPath = Server.MapPath("inc/info.xml")
    '判断文件是否存在
    Set objDom = Server.CreateObject("Microsoft.XMLDom")
    objDom.async = false
    If not objDom.load(xmlPath) Then
        Set objRoot = objDom.CreateElement("xml")
        objDom.appendChild objRoot
        objRoot.SelectSingleNode("//xml").appendChild objDom.CreateElement("login")
        objRoot.SelectSingleNode("//xml/login").SetAttributeNode objDom.CreateNode("attribute","date","")
        objRoot.SelectSingleNode("//xml/login/@date").text = FormatDate
    Else
        Set objRoot = objDom.documentElement
    End if
    '判断是否有当天的登录节点,没有就添加
    Set objTemp = objRoot.SelectSingleNode("//xml").childNodes.item(objDom.SelectSingleNode("//xml").childNodes.length-1).GetAttributeNode("date")
    If objTemp.nodevalue <> FormatDate Then
        Set objTemp2 = objDom.CreateElement("login")
        Set objAtt = objDom.CreateNode("attribute","date","")
        objAtt.Text = FormatDate
        objTemp2.SetAttributeNode objAtt
        objRoot.appendChild objTemp2
    End If
    '添加用户登录信息
    Set objTemp3 = objRoot.SelectSingleNode("//xml/login[@date='" & FormatDate & "']")
    Set objTemp4 = objDom.CreateElement("user")
    objTemp4.text = user
    objTemp4.SetAttributeNode objDom.CreateNode("attribute","time","")
    objTemp4.GetAttributeNode("time").NodeValue = hour(now()) & ":" & minute(now()) & ":" & second(now())
    objTemp3.appendChild objTemp4
    objDom.save xmlPath
End Function
'==========登记结束  访问:inc/info.xml==========


在ChkUserLogin函数中查找"If EnabledSession Then     Session(Dvbbs.CacheName & "UserID")=Dvbbs.UserSession.xml",在此句后添加:
WriteLogin (Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@username").text)
保存即可!

访问列表文件查看:inc/info.xml

评论: 1 | 引用: 0 | 查看次数: 4094
发表评论
登录后再发表评论!