首页 域名主机 文章教程 汽车频道 酷车图集 博客之家 网址之家 资源下载 在线音乐 本站论坛
  你现在的位置:首页>>文章教程>>网页编程>>ASP教程>>正文
 
完整的访问统计程序(二  程序篇)
 
[2004-12-30] 来源: 作者:极点学网收集整理  爱我梅州商务网 
 

/*
  原创:豆腐
  请大家在转载和使用的时候  保留这条信息
*/
/* 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= amp; uid amp; ;PWD= amp; pwd amp; ;database= amp; db amp; ;server= amp; Softserver amp;
     
     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) amp; 点-- amp; cstr(i+1) amp; 点
   next
   i=0
   set rst=openRst()
   strSQL=select sum(num) as ccount from dateStatic where userid=' amp; userid amp; '
   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=' amp; userid amp; ' 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=' amp; userid amp; '
   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=' amp; userid amp; ' 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) amp; 日
   next
   i=0
   strSQL=select sum(num) as ccount from MonthStatic where userid=' amp; userid amp; '
   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=' amp; userid amp; ' 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) amp; 月
   next
   i=0
   strSQL=select sum(num) as ccount from YearStatic where userid=' amp; userid amp; '
   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=' amp; userid amp; ' 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=' amp; userid amp; ' 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=' amp; userid amp; '
      Rst.open strSQL,Conn,3,1
      TotalVisit=rst(0)
      StrSQL=select BrowserType,count(BrowserType) as visitcount from AccessStat where userid=' amp; userid amp; ' 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="http://test.lovemz.com/Files/article/059201274985500.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:// amp; Request.ServerVariables(SERVER_NAME) amp; Request.ServerVariables(SCRIPT_NAME)
      end if
      strIPAddr=Request.ServerVariables (REMOTE_ADDR)        '用户IP地址
      strSQL=insert into AccessStat(UserID,VisitTime,IPAddr,UseSystem,BrowserType,LastPage)
      strSQL=strSQL amp; values (' amp; trim(userid) amp; ',getDate(),' amp; trim(strIPAddr) amp; ','
      strSQL=strSQL amp; trim(strUseSystem) amp; ',' amp; trim(strBrowserName) amp; ',' amp; trim(strPrPage) amp; ')
      conn.execute strSQL
   end sub
%>
<%
   sub ExecDayStatic(userid)
      '处理每日的小时数据
      strSQL=select * from DateStatic where dateid=datepart(dy,getdate()) and userid=' amp; userid amp; '
      set rst=openrst()
      rst.open strSQL,conn,3,3
      if rst.eof and rst.bof then
         strSQL=delete from DateStatic where userid=' amp; userid amp; '
         conn.execute strSQL
         for i=0 to 23
            strSQL=insert into DateStatic values(datepart(dy,getdate()), amp; cStr(i) amp; ,' amp; userid amp; ',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=' amp; userid amp; '
      conn.execute strSQL      
   end sub
%>
<%
   sub ExecWeekStatic(userid)
     '处理每周的日数据
     strSQL=select * from WeekStatic where weekid=datepart(ww,getdate()) and userid=' amp; userid amp; '
     set rst=openRst()
     rst.open strSQL,conn,3,3
     if rst.eof and rst.bof then
        strSQL=delete from WeekStatic  where userid=' amp; userid amp; '
        conn.execute strSQL
        for i=0 to 6
           strSQL=insert into WeekStatic values(datepart(ww,getdate()), amp; cStr(i) amp; ,' amp; userid amp; ',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=' amp; userid amp; '
     conn.execute strSQL
  end sub
%>
<%
   sub ExecMonthStatic(userid)
      '处理每月的日数据
      strSQL=select * from MonthStatic where monthid=datepart(mm,getdate()) and userid=' amp; userid amp; '
      set rst=openRst()
      rst.open strSQL,conn,3,3
      if rst.eof and rst.bof then
         strSQL=delete from MonthStatic  where userid=' amp; userid amp; '
         conn.execute strSQL
         for i=1 to 31
            strSQL=insert into MonthStatic values(datepart(mm,getdate()), amp; cStr(i) amp; ,' amp; userid amp; ',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=' amp; userid amp; '
      set rst=openRst()
      rst.open strSQL,conn,3,3
      if rst.eof and rst.bof then
         strSQL=delete from YearStatic where userid=' amp; userid amp; '
         conn.execute strSQL
         for i=1 to 12
            strSQL=insert into YearStatic values(datepart(yy,getdate()), amp; cStr(i) amp; ,' amp; userid amp; ',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=' amp; userid amp; '
      conn.execute strSQL
   end sub
%gt
 
上一篇文章:完整的访问统计程序(三  应用篇)
下一篇文章:完整的站点访问统计系统(一:数据库篇)
本文章为原作者版权所有,如有侵犯您的权益请通知我们,我们会在24小时以内删除
最新5篇热点文章
最新5篇推荐文章
相关文章
完整的站点访问统计系统(一:数据库
完整的访问统计程序(三  应用篇)

关于我们 | 广告刊登 | 合作伙伴 | 友情链接 | 意见反馈 | 帮助HELP| 网站地图

版权所有 Copyright © 2002-2005 爱我梅州商务网
粤ICP备05105236号