<!--#include file="../Include/Const.asp" -->
<!--#include file="../Include/Conn.asp" -->
<%
    Dim C_ip,C_where,C_city,C_come,C_page,C_brower,C_os,C_oss,C_browers
    Dim C_year,C_month,C_day,C_hour,C_time,C_week
    C_ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If C_ip = "" Then C_ip = Request.ServerVariables("REMOTE_ADDR")
    C_browers = Request.ServerVariables("HTTP_USER_AGENT")
    if Instr(C_browers,"NetCaptor 6.5.0") Then
        C_brower = "NetCaptor 6.5.0"
    ElseIf Instr(C_browers,"MyIe 3.1") Then
        C_brower = "MyIe 3.1"
    ElseIf Instr(C_browers,"NetCaptor 6.5.0RC1") Then
        C_brower = "NetCaptor 6.5.0RC1"
    ElseIf Instr(C_browers,"NetCaptor 6.5.PB1") Then
        C_brower = "NetCaptor 6.5.PB1"
    ElseIf Instr(C_browers,"MSIE 5.5") Then
        C_brower = "Internet Explorer 5.5"
    ElseIf Instr(C_browers,"MSIE 6.0") Then
        C_brower = "Internet Explorer 6.0"
    ElseIf Instr(C_browers,"MSIE 7.0") Then
        C_brower = "Internet Explorer 7.0"
    ElseIf Instr(C_browers,"MSIE 6.0b") Then
        C_brower = "Internet Explorer 6.0B"
    ElseIf Instr(C_browers,"MSIE 5.01") Then
        C_brower = "Internet Explorer 5.01"
    ElseIf Instr(C_browers,"MSIE 5.0") Then
        C_brower = "Internet Explorer 5.00"
    ElseIf Instr(C_browers,"MSIE 4.0") Then
        C_brower = "Internet Explorer 4.01"
    Else
        C_brower = "其它浏览器"
    End If
    C_oss = Request.ServerVariables("HTTP_USER_AGENT")
    If Instr(C_oss,"NT 5.1") Then
        C_os = "Windows XP"
    ElseIf Instr(C_oss,"Tel") Then
        C_os = "Telport"
    ElseIf Instr(C_oss,"webzip") Then
        C_os = "webzip"
    ElseIf Instr(C_oss,"flashget") Then
        C_os = "flashget"
    ElseIf Instr(C_oss,"offline") Then
        C_os = "offline"
    ElseIf Instr(C_oss,"NT 5") Then
        C_os = "Windows 2000"
    ElseIf Instr(C_oss,"NT 4") Then
        C_os = "Windows NT4"
    ElseIf Instr(C_oss,"98") Then
        C_os = "Windows 98"
    ElseIf Instr(C_oss,"95") Then
        C_os = "Windows 95"
    ElseIf Instr(C_oss,"unix") Or Instr(C_oss,"linux") Or Instr(C_oss,"SunOS") or Instr(C_oss,"BSD") Then
        C_os = "类Unix"
    ElseIf Instr(C_oss,"Mac") Then
        C_os = "Mac"
    Else
        C_os = "其它系统"
    End If
    C_come = request("referer")
    If C_come = "" Then
        C_come = "直接输入网址或收藏夹打开"
    End If
    C_page = Request.ServerVariables("HTTP_REFERER")
    C_year = year(now())
    C_month = month(now())
    C_day = day(now())
    C_hour = hour(now())
    C_time = now()
    C_week = weekday(now())
    Dim dbpath,connstr1,conn1,rs1
    dbpath = ""&AngelSysRootDir&"Count/AddressIp.mdb"
    connstr1 = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "&Server.MapPath(dbpath)
    Set conn1 = Server.CreateObject("Adodb.Connection")
    conn1.open connstr1
    If Err Then
        Err.Clear
        Set Conn1 = Nothing
        Response.Write "数据库连接错误"
        Response.End
    End If
    Dim c_ipnow
    c_ipnow = CLngIP(C_ip)
    sqlip = "select * from Address where StarIP <= "&c_ipnow&" and EndIP >= "&c_ipnow&""
    Set rsip = Server.CreateObject("ADODB.RecordSet")
    rsip.open sqlip,conn1,1,1
    If Not(rsip.bof And rsip.eof) Then
        C_where = rsip("Country")
        C_city = rsip("City")
    Else
        C_where = "未知"
        C_city = ""
    End If
    rsip.close
    Set rsip = Nothing
    conn1.close
    Set conn1 = Nothing
	set rs = Server.CreateObject("ADODB.RecordSet")
    sql = "select * from Angel_Count"
	rs.open sql,conn,1,3
	rs.addnew
	rs("C_ip")=C_ip
	rs("C_where")=C_where
	rs("C_city")=C_city
	rs("C_come")=C_come
	rs("C_page")=C_page
	rs("C_brower")=C_brower
	rs("C_os")=C_os
	rs("C_year")=C_year
	rs("C_month")=C_month
	rs("C_day")=C_day
	rs("C_hour")=C_hour
	rs("C_time")=C_time
	rs("C_week")=C_week
    rs.update
	rs.close
	set rs=nothing
	'set conn=nothing
    sqlnum = "select * from Angel_Countnum"
    Set rsnum = conn.execute(sqlnum)
    n1 = 1
    n2 = 0
    If (rsnum.bof And rsnum.eof) Then
        sql1 = "Insert into Angel_Countnum(N_today,N_yesterday,N_total,N_time) values('"&n1&"','"&n2&"','"&n1&"','"&date()&"')"
        conn.execute(sql1)
    Else
        On Error Resume Next
        N_time = rsnum("N_time")
        dd = DateDiff("d",N_time,date())
        Select Case dd
            Case 0
                sqln = "update Angel_Countnum set N_today = N_today + 1,N_total = N_total + 1"
            Case 1
                sqln = "update Angel_Countnum set N_today = 1,N_yesterday = '"&rsnum("N_today")&"',N_time = '"&date()&"',N_total = N_total + 1"
            Case Else
                sqln = "update Angel_Countnum set N_today = 1,N_yesterday = 0,N_time = '"&date()&"',N_total = N_total + 1"
        End Select
        conn.execute(sqln)
    End If
    rsnum.close
    Set rsnum = Nothing
    sqltotal = "select * from Angel_Countnum"
    Set rstotal = conn.execute(sqltotal)
    N_today = rstotal("N_today")
    N_yesterday = rstotal("N_yesterday")
    N_totals = rstotal("N_total")
    rstotal.close
    Set rstotal = Nothing
    Function CLngIP(ByVal asNewIP)
        Dim lnResults
        Dim lnIndex
        Dim lnIpAry
        lnIpAry = Split(asNewIP, ".", 4)
        For lnIndex = 0 To 3
        If Not lnIndex = 3 Then
        lnIpAry(lnIndex) = lnIpAry(lnIndex) * (256 ^ (3 - lnIndex))
        End If
        lnResults = lnResults + lnIpAry(lnIndex)
        Next
        CLngIP = lnResults
    End Function
    style = request("style")
    Select Case style
        Case "counter"
        Case "text"
            s = N_totals
    End Select
    response.write "document.write ('"&s&"');"
%>