教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> ASP >> 用ASP建立WEB页面计数器 RSS订阅
用ASP建立WEB页面计数器
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   

用ASP建立WEB页面的计数器通常有两种简单的方法,一个是建立global.asa,另外一个是直接写一个ASP文件来进行计数。一般使用一个文档来保存浏览数量。
    1、用global.asa来写计数器写一个global.asa文件,存放到虚拟目录的根目录下面,源代码如下:


   <Script language ="Vbscript" Runat="server">
  sub Application_onStart()
    countFile=server.mappath("counter")+"/counter.txt"
    set fso=Server.CreateObject("Scripting.FileSystemObject")
    set file=fso.OpenTextFile("countFile")
      读取访问数并赋给Application变量number
    Application("number")=file.readLine
    file.close
  end sub
    sub session_onStart()
      If IsEmpty(Session("hasbeenConnected")) then
        Application.Lock
      Application("number")=Application("number")+1
      Applicaiotn.Unlock
      end if
      Session("hasbeenConnected")=True
    end sub
  sub Application_onEnd()
    countFile=server.mappath("counter")+"/counter.txt"
    set fso=Server.CreateObject("Scripting.FileSystemObject")
    set file=fso.CreateTextFile("countFile",true)
     使用writeLine方法写入当前值
    file.writeLine(Application("number"))
    file.close
  end sub
  </script>
    调用计数器时候在网页中写入<%response.Write("你是第"&number&"位访问者!")%>即可,不过调用网页也必须是ASP页面。这种方法有缺点,就是好多个人主页空间并不支持运行global.asa,即不是为用户建的虚拟目录,所以无法正确运行。

 

    2、直接写一个counter.asp来计数我自己现在用的计数器就是这样,而且可以在任何页面中调用,调用方法是:

  <scriptsrc="http://xxx.xxx.xxx/counter.asp?id=abc&num=6&style=1"></script >

||||||
网站推广:购物信息革命--价格网    域名转让 来溜溜论坛,送QQ币!!
证明有你们在我的身边
 
   其中id=abc表示用户名为abc,那么要建立counter/abc.txt存放计数值;
       num=6为计数器的显示位数;
       style=1为计数器风格,建立counter/style1/0~9.gif即可,可以增加多种风格。

   源代码如下:

<%
set fso=server.CreateObject("Scripting.FileSystemObject")
filepath=server.mappath("counter")+"/"+request("id")+".txt"
set temp=fso.opentextfile(filepath,1)
count=temp.readline
temp.close
if isempty(session("connected")) then
  set temp=fso.opentextfile(filepath,2)
  application.lock
  count=count+1
  temp.writeline(count)
  application.unlock
  temp.close
end if
set temp=nothing
set fso=nothing
session("connected")=true
numlength=len(count)
if request("num")="" then
  maxnum=6
else
  maxnum=cint(request("num"))
end if
if request("style")="" then
  style="1"
else
  style=request("style")
end if
for i=1 TO maxnum STEP 1
  If i<=maxnum-numlength  then
    countimage="<img src=http://xxx.xxx.xxx/counter/style"&style&"/0.gif width=15 height=20></img>"
    response.write "document.write( "&countimage&" );"
  Else
    countimage="<img src=http://xxx.xxx.xxx/counter/style"&style&"/"& mid(count,i-(maxnum-numlength),1)&".gif width=15 height=20></img>"
    response.write "document.write( "&countimage&" );"

End If
next
%>

来源:upschool.cn
作者:
关键字:
发表日期:2006-7-26

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:利用ASP在线维护数据库   下一篇:教你用好活动字幕标记--Marquee


2009-1-9 19:58:24
本文的相类似文章
在学习中进步 在进步中成长 教程中国相随您的成长之路
华腾联合科技股份有限公司版权所有
广告联系:Rosibo@163.com