<!--#include file="conncounter.asp" -->
<%
Response.Expires = 0
sql="Select top 1 thisdate from ip"
set rs=conn.execute(sql)
If rs.eof and rs.bof Then                   
Else
date1=rs(0)
if cstr(date1)<>cstr(date) then
sql1="select * from cnt where id =1"                 
set rs1=server.createobject("adodb.recordset")                  
rs1.open sql1,conn,1,1
day2ip=rs1("yesdayip")
day2pv=rs1("yesdaypv")
rs1.close
set rs1=nothing
yesdayip=todayip()
yesdaypv=todaypv()
sql2="update cnt set day2ip="&day2ip&",day2pv="&day2pv&",yesdayip="&yesdayip&",yesdaypv="&yesdaypv&",totalip=totalip+"&yesdayip&",totalpv=totalpv+"&yesdaypv&" where id = 1"
conn.execute(sql2)
sqlip="Delete FROM ip"
Conn.Execute sqlip
sqlurl="Delete FROM urls"
Conn.Execute sqlurl
sqlcome="Delete from comes"
Conn.Execute sqlcome
end if
end if
rs.close
set rs=nothing
dim id
id=replace(Request.ServerVariables("REMOTE_HOST"),".","")
if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then
id=replace(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),".","")
end if
sql="select id from ip where id='"&id&"'"
set rs=conn.execute(sql)
if rs.eof and rs.bof then
sql="insert into ip(id,ip,dlip,startime,lastime,browser,url) values ('"&id&"','"&Request.ServerVariables("REMOTE_HOST")&"','"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")&"',now(),now(),'"&Request.ServerVariables("HTTP_USER_AGENT")&"','"&Request.ServerVariables("HTTP_REFERER")&"')"
else
sql="update ip set lastime=now(),url='"&Request.ServerVariables("HTTP_REFERER")&"',n=n+1 where id='"&id&"'"
end if
conn.execute(sql)
rs.close
set rs=nothing
dim url
url=Request.ServerVariables("HTTP_REFERER")
if url="" then
url="直接输入访问"
end if
if len(url)>240 then
url=left(url,240)
end if
sql="select url from urls where url='"&url&"'"
set rs=conn.execute(sql)
if rs.eof and rs.bof then
sql="insert into urls(url) values ('"&url&"')"
else
sql="update urls set n=n+1 where url='"&url&"'"
end if
conn.execute(sql)
rs.close
set rs=nothing
function online()
sql="Select count(id) from ip WHERE DATEDIFF('s', lastime, now()) < "&kicktime&"*60"
set ips=conn.execute(sql) 
online=ips(0)
ips.close
set ips=nothing 
if isnull(online) then 
online=0
end if
end function 
function todayip()
sql="Select count(id) from ip"
set ipss=conn.execute(sql) 
todayip=ipss(0)
ipss.close 
set ipss=nothing 
if isnull(todayip) then 
todayip=0
end if
end function
function todaypv()
sql="Select sum(n) from ip"
set rs=conn.execute(sql)
If rs.eof and rs.bof Then 
todaypv=0                    
Else
todaypv=rs(0)
end if
rs.close
set rs=nothing 
end function 
Function finddir(filepath)
finddir=""
for i=1 to len(filepath)
if left(right(filepath,i),1)="/" or left(right(filepath,i),1)="\" then
  abc=i
  exit for
end if
next
if abc <> 1 then
finddir=left(filepath,len(filepath)-abc+1)
end if
end Function
theurl="http://" & Request.ServerVariables("http_host") & finddir(Request.ServerVariables("url"))
Response.Write "document.write('Online:"& online() &"　TodayIP:"&todayip()&"　TodayPV:"&todaypv()&"')"
conn.close
set conn=nothing
%>
document.write("<script>var url='<%=theurl%>';</script>")
document.write("<script language=javascript src="+url+"/stat.asp?referer="+escape(document.referrer)+"></script>");