/*
原创:豆腐
请大家在转载和使用的时候 保留这条信息
*/
/* dbcn.asp
创建数据库连接的 公用程序
*/
<%
function openconn()
创建数据库连接
dim connstr
dim uid
dim pwd
dim db
uid="bbc"
pwd="bbc"
db="bbc"
softserver="softdepserver"
set conn = server.createobject("adodb.connection")
connstr="provider=sqloledb.1;uid=" & uid & ";pwd=" & pwd & ";database=" & db & ";server=" & softserver & ""
conn.open connstr
set openconn=conn
end function
function openrst()
创建数据库记录集
set rst=server.createobject ("adodb.recordset")
set openrst=rst
end function
%>
/*
staticfunc
统计程序所需要用到的函数库
*/
<!–#include file="dbcn.asp"–>
<%
set conn=openconn()
set rst=openrst()
sub writedatetable(intstart,intend,strarray,ccount)
生成统计表
%>
<table border=1 width=100%>
<%for i= intstart to intend%>
<tr>
<td width=30%><%=strarray(i)%></td>
<td width=60%>
<%
if rst.eof then
setbar 0,ccount
else
if rst(1)=i then
setbar rst(3),ccount
if not rst.eof then rst.movenext
else
setbar 0,ccount
end if
end if
%>
</td>
</tr>
<%next%>
</table>
<%
end sub
%>
<%
sub setbar(num,ccount)
生成统计条
if ccount=0 then
percent=0
else
percent=cint(num/ccount*10000)/100
end if
strgif="bar.gif"
%>
<img src="<%=strgif%>" width="<%=percent+5%>" height=10><font color=red><%=percent%>%</font>
<td align=center>
<%=num%>
</td>
<%
end sub
%>
<%
sub writedaystatic(userid)
生成日统计
i=0
dim strarray(100)
for i=0 to 23
strarray(i)= cstr(i) & "点–" & cstr(i+1) & "点"
next
i=0
set rst=openrst()
strsql="select sum(num) as ccount from datestatic where userid=" & userid & ""
rst.open strsql,conn,3,3
if isnull(rst("ccount")) then
ccount=0
else
ccount=rst("ccount")
end if
strsql="select * from datestatic where userid=" & userid & " order by hourid"
set rst=openrst()
rst.open strsql,conn,3,3
%>
访问总数<%=ccount%>
<table border=1 width=100%>
<tr height=100%>
<td width=50%><% writedatetable 0, 11, strarray ,ccount %></td>
<td width=50%><%writedatetable 12, 23, strarray ,ccount %></td>
</tr>
</table>
<%
end sub
%>
<%
sub writeweekstatic(userid)
生成周统计
i=0
dim strarray(7)
strarray(0)="星期日"
strarray(1)="星期一"
strarray(2)="星期二"
strarray(3)="星期三"
strarray(4)="星期四"
strarray(5)="星期五"
strarray(6)="星期六"
i=0
strsql="select sum(num) as ccount from weekstatic where userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if isnull(rst("ccount")) then
ccount=0
else
ccount=rst("ccount")
end if
strsql="select * from weekstatic where userid=" & userid & " order by dayid"
set rst=openrst()
rst.open strsql,conn,3,3
%>
访问总数<%=ccount%>
<table border=1 width=100%>
<tr height=100%>
<td width=100%><% writedatetable 0, 6, strarray ,ccount %></td>
</tr>
</table>
<%
end sub
%>
<%
sub writemonthstatic(userid)
生成月统计
i=0
dim strarray(32)
for i=1 to 31
strarray(i)=cstr(i) & "日"
next
i=0
strsql="select sum(num) as ccount from monthstatic where userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if isnull(rst("ccount")) then
ccount=0
else
ccount=rst("ccount")
end if
strsql="select * from monthstatic where userid=" & userid & " order by dayid"
set rst=openrst()
rst.open strsql,conn,3,3
%>
访问总数<%=ccount%>
<table border=1 width=100%>
<tr height=100%>
<td width=50%><% writedatetable 1, 16, strarray ,ccount %></td>
<td width=50%><% writedatetable 17, 31, strarray ,ccount %></td>
</tr>
</table>
<%
end sub
%>
<%
sub writeyearstatic(userid)
i=0
dim strarray(13)
for i=1 to 12
strarray(i)=cstr(i) & "月"
next
i=0
strsql="select sum(num) as ccount from yearstatic where userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if isnull(rst("ccount")) then
ccount=0
else
ccount=rst("ccount")
end if
strsql="select * from yearstatic where userid=" & userid & " order by monthid"
set rst=openrst()
rst.open strsql,conn,3,3
%>
访问总数<%=ccount%>
<table border=1 width=100%>
<tr height=100%>
<td width=50%><% writedatetable 1, 6, strarray ,ccount %></td>
<td width=50%><% writedatetable 7, 12, strarray ,ccount %></td>
</tr>
</table>
<%
end sub
%>
<%
sub writerecentinfo(userid)
显示访问者的浏览器分布
strsql="select top 10 * from accessstat where userid=" & userid & " order by visittime desc"
set rst=openrst()
rst.open strsql,conn,3,1
%>
<table border=1 width=100% align=center cellspacing=1 cellpadding=1>
<tr>
<td width=5% align=center>序 号</td>
<td width=20% align=center>来访时间</td>
<td width=15% align=center>ip地址</td>
<td width=15% align=center>所用操作系统</td>
<td width=15% align=center>所用浏览器类型</td>
<td width=30% align=center>浏览的上一页</td>
<td width=0%></td>
</tr>
<% for i=1 to rst.recordcount %>
<tr>
<td width=5% align=center><%=i%></td>
<td width=20% align=center><%=rst("visittime")%></td>
<td width=15% align=center><%=rst("ipaddr")%></td>
<td width=15% align=center><%=rst("usesystem")%></td>
<td width=15% align=center><%=rst("browsertype")%></td>
<td width=30% align=center><a href=<%=rst("lastpage")%>><%response.write rst("lastpage")%></a></td>
<td width=0%></td>
</tr>
<% rst.movenext%>
<% next %>
</table>
<%
end sub
%>
<%
sub writebrowserinfo(userid)
set rst=openrst()
strsql="select count(*) as visitcount from accessstat where userid=" & userid & ""
rst.open strsql,conn,3,1
totalvisit=rst(0)
strsql="select browsertype,count(browsertype) as visitcount from accessstat where userid=" & userid & " group by browsertype order by visitcount desc"
set rst=openrst()
rst.open strsql,conn,3,1
%>
<table border=1 width=100% align=center cellspacing=1 cellpadding=1>
<tr>
<td width=5% align=center>序 号</td>
<td width=15% align=center>所用浏览器类型</td>
<td width=40% align=center>访问比例尺表示</td>
<td width=15% align=center>访问次数</td>
<td width=5%></td>
</tr>
<%for i=1 to rst.recordcount %>
<tr>
<td width=5% align=center><%=i%></td>
<td width=15% align=center><%=rst("browsertype")%></td>
<!–
<td width=15% align=center><%=rst("visitcount")%></td>
<td width=10% align=center><%=formatnumber(cint(rst("visitcount")/totalvisit*10000)/100,true,true)%>%</td>
<td width=40% align=left><img src=bar.gif width=<%=(rst("visitcount")/totalvisit)*300%> height=10></td>
–>
<td><%setbar rst("visitcount"),totalvisit %></td>
<td width=5% ></td>
</tr>
<%rst.movenext%>
<% next %>
</table>
<%
end sub
%>
<%
sub insertdata(userid)
处理浏览者信息
execuserinfo userid
处理日统计
execdaystatic userid
处理周统计
execweekstatic userid
处理月统计
execmonthstatic userid
处理年统计
execyearstatic userid
end sub
%>
<%
sub execuserinfo(userid)
处理浏览者信息
strret=request.servervariables("http_user_agent")
strarray=split(strret,"(")
strret=left(strarray(1),len(strarray(1))-1)
strarray=split(strret,";")
strbrowsername=strarray(1) 浏览器
strusesystem=strarray(2) 用户操作系统
strprpage=request.servervariables("http_referer") 从何而来
if strprpage="" then
strprpage="http://" & request.servervariables("server_name") & request.servervariables("script_name")
end if
stripaddr=request.servervariables ("remote_addr") 用户ip地址
strsql="insert into accessstat(userid,visittime,ipaddr,usesystem,browsertype,lastpage) "
strsql=strsql & "values (" & trim(userid) & ",getdate()," & trim(stripaddr) & ","
strsql=strsql & trim(strusesystem) & "," & trim(strbrowsername) & "," & trim(strprpage) & ")"
conn.execute strsql
end sub
%>
<%
sub execdaystatic(userid)
处理每日的小时数据
strsql="select * from datestatic where dateid=datepart(dy,getdate()) and userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if rst.eof and rst.bof then
strsql="delete from datestatic where userid=" & userid & ""
conn.execute strsql
for i=0 to 23
strsql="insert into datestatic values(datepart(dy,getdate())," & cstr(i) & "," & userid & ",0)"
conn.execute strsql
next
end if
strsql="update datestatic set num=num + 1 where dateid=datepart(dy,getdate()) and hourid= datepart(hh,getdate()) and userid=" & userid & ""
conn.execute strsql
end sub
%>
<%
sub execweekstatic(userid)
处理每周的日数据
strsql="select * from weekstatic where weekid=datepart(ww,getdate()) and userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if rst.eof and rst.bof then
strsql="delete from weekstatic where userid=" & userid & ""
conn.execute strsql
for i=0 to 6
strsql="insert into weekstatic values(datepart(ww,getdate())," & cstr(i) & "," & userid & ",0)"
conn.execute strsql
next
end if
strsql="update weekstatic set num=num + 1 where weekid=datepart(ww,getdate()) and dayid+1= datepart(dw,getdate()) and userid=" & userid & ""
conn.execute strsql
end sub
%>
<%
sub execmonthstatic(userid)
处理每月的日数据
strsql="select * from monthstatic where monthid=datepart(mm,getdate()) and userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if rst.eof and rst.bof then
strsql="delete from monthstatic where userid=" & userid & ""
conn.execute strsql
for i=1 to 31
strsql="insert into monthstatic values(datepart(mm,getdate())," & cstr(i) & "," & userid & ",0)"
conn.execute strsql
next
end if
strsql="update monthstatic set num=num + 1 where monthid=datepart(mm,getdate()) and dayid= datepart(dd,getdate())"
conn.execute strsql
end sub
%>
<%
sub execyearstatic(userid)
处理每年的月数据
strsql="select * from yearstatic where yearid=datepart(yy,getdate()) and userid=" & userid & ""
set rst=openrst()
rst.open strsql,conn,3,3
if rst.eof and rst.bof then
strsql="delete from yearstatic where userid=" & userid & ""
conn.execute strsql
for i=1 to 12
strsql="insert into yearstatic values(datepart(yy,getdate())," & cstr(i) & "," & userid & ",0)"
conn.execute strsql
next
end if
strsql="update yearstatic set num=num + 1 where yearid=datepart(yy,getdate()) and monthid= datepart(mm,getdate()) and userid=" & userid & ""
conn.execute strsql
end sub
%>
