<!--#include file="../conn/conn.asp"-->
<!--#include file="../Inc/Commoncode.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
	
	'获取浏览客户端ip
	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())

	'链接ip地址库，查询访问者来自地区，城市
	dim dbpath,connstr1,conn1,rs1
	dbpath="../database/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 "<br><br><br><br><br><br><br><div align='center'>数据库连接出错，错误编号10001。</div>"
        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

	'把访问记录写如到数据库
	sql="Insert into JOB_Count(C_ip,C_where,C_city,C_come,C_page,C_brower,C_os,C_year,C_month,C_day,C_hour,C_time,C_week) values('"&C_ip&"','"&C_where&"','"&C_city&"','"&C_come&"','"&C_page&"','"&C_brower&"','"&C_os&"','"&C_year&"','"&C_month&"','"&C_day&"','"&C_hour&"','"&C_time&"','"&C_week&"')"
	conn.execute(sql)
	
	'更改记录到数据表JOB_Countnum
	sqlnum="select * from JOB_Countnum"
	set rsnum=conn.execute(sqlnum)
	n1=1
	n2=0
	if (rsnum.bof and rsnum.eof) then
		sql1="Insert into JOB_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 JOB_Countnum set N_today=N_today+1,N_total=N_total+1"
			case 1
				sqln="update JOB_Countnum set N_today=1,N_yesterday='"&rsnum("N_today")&"',N_time='"&date()&"',N_total=N_total+1"
			case else
				sqln="update JOB_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 JOB_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
CloseConn
'********************************************************
'转换IP   IP--LNG
'********************************************************
	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 
%>
<%
	'统计样式在前台的显示
	'调用方式
	'把代码：<script src="http://192.168.1.203/v602/count/mycount.asp?style=text"><//script>放置于需要统计的页面
	style=request("style")
	Select Case style
		case "counter"
			
		case "text"
			s=N_totals
	End Select
	response.write "document.write ('"&s&"');"
%>