建一个表:clicktable(一个字段clicknum)
然后在需要统计的页面加上
<%
if request.cookies("counter")="" then
response.cookies("counter")="visited"
conn.execute "update clicktablbe set clicknum=clicknum+1"
end if
%>
这个统计可以防止简单的刷新
建立一个counter文本文件
<%
Sub application_OnStart()
set fs=server.CreateObject("Scripting.FileSystemObject")
counter_file = server.MapPath("counter.txt")
set txt = fs.OpenTextFile(counter_file)
application("counter")=txt.readline
txt.close
end sub
Sub application_OnEnd
set fs=server.CreateObject("Scripting.FileSystemObject")
counter_file = server.MapPath("counter.txt")
set txt=fs.OpenTextFile(counter_file)
set txt=fs.CreateTextFile(counter_file,true)
txt.writeLine(application("counter"))
txt.close
end sub
%>
<%
if isempty(session("connected")) then
application.Lock()
application_OnStart()
application("counter")=application("counter")+1
application_OnEnd
application.UnLock()
end if
session("connected")=true
%>
应在GLOBAL.ASA中写:
<Script Language="VBScript" RunAt="Server">
Sub Application_OnStart()
Application.Lock
Application("Currentusers")=0
Application.Unlock
End Sub
Sub Session_OnStart()
Dim f1,t1,file
Application.Lock
Set f1=Server.CreateObject("Scripting.FileSystemObject")
file="d:count.txt"
Set t1=f1.OpenTextFile(file,1,-1,0)
writetof=Clng(t1.Readline)
t1.Close
writetof=writetof+1
Set t1=f1.CreateTextFile(file,-1,0)
t1.WriteLine writetof
t1.Close
Application.Unlock
Session.Timeout=30
Session("flag")=false
Application.Lock
Application("Currentusers")=Application("Currentusers")+1
Application.UnLock
End Sub
Sub Session_OnEnd()
Application.Lock
Application("Currentusers")=Application("Currentusers")-1
Application.unlock
End Sub
Sub Application_OnEnd()
End Sub
</Script>
这样在线人数和计数都可以了
以下是我自己用的一个最简单的计数器。
相关网址:
http://www.donfor.com/book_cklr.asp?dfzxonkey=kdjsfa=2&js=487&dlj=ljz&lable=59
代码如下:
if session("jsq")="" then
sqljsq="select * from abouttable where id=1"
set dbrsjsq=dbconn.execute(sqljsq)
jsq01=dbrsjsq(2).value
jsq01=jsq01+1
session("jsq")=jsq01
sqljsq01="update abouttable set blz='"& jsq01 &"' where id=1"
dbconn.execute(sqljsq01)
dbrsjsq.close
set dbrsjsq=nothing
end if
sub gcounter
aa=session("jsq")
counts=Cint(aa)
digits=5
for i=digits-1 to 0 step -1
temp=fix(counts/10^i)
response.write"<img src=jsq/"&temp&".gif>"
counts=counts-temp*10^i
next
end sub