剛才找一個(gè)計(jì)數(shù)器,由于網(wǎng)站的訪問量太少,放個(gè)計(jì)數(shù)器在那里確實(shí)有點(diǎn)寒酸了,于是呼只能搞一個(gè)簡單點(diǎn)的,可以訪問一次就記錄一次的來撐撐門面先。本來以前我有一個(gè),但是郁悶的是居然找不到了,在網(wǎng)上SO了一圈,總算是搞定了,具體程序代碼如下。
count.asp的代碼為:
復(fù)制代碼 代碼如下:
%
option explicit
dim fs,filename,txt,content,total,counter_lenth
counter_lenth=1 '設(shè)置顯示數(shù)據(jù)的最小長度,如果小于實(shí)際長度則以實(shí)際長度為準(zhǔn)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
if not fs.FileExists(filename) then
fs.CreateTextFile filename,True,True
set txt=fs.OpenTextFile(filename,2,true)
txt.write 0 '如不存在保存數(shù)據(jù)的文件則創(chuàng)建新文件并寫入數(shù)據(jù)0
set fs=nothing
end if
set txt=fs.OpenTextFile(filename)
If txt.AtEndOfStream Then
Application("Counter")=0 '如果文件中沒有數(shù)據(jù),則初始化Application("Counter")的值(為了容錯(cuò))
else
Application("Counter")=txt.readline
end if
Application.Lock
Application("Counter") = Application("Counter") + 1
Application.UnLock
Function save_ '保存計(jì)數(shù)函數(shù)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
content=Application("Counter")
set txt=fs.OpenTextFile(filename,2,true)
txt.write content
set fs=nothing
End Function
save_ '調(diào)用保存函數(shù)保存數(shù)據(jù)
Function Digital ( counter ) '顯示數(shù)據(jù)函數(shù)
Dim i,MyStr,sCounter
sCounter = CStr(counter)
For i = 1 To counter_lenth - Len(sCounter)
MyStr = MyStr "0"
'MyStr = MyStr "IMG SRC=改成你自己的圖片存放的相對目錄\0.gif>" '如有圖片,可用此語句調(diào)用
Next
For i = 1 To Len(sCounter)
MyStr = MyStr Mid(sCounter, i, 1)
'MyStr = MyStr "IMG SRC=改成你自己的圖片存放的相對目錄\" Mid(sCounter, i, 1) ".gif>" '如有圖片,可用此語句調(diào)用
Next
Digital = MyStr
End Function
Function count_show '讀取計(jì)數(shù)函數(shù)
set fs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
set txt=fs.opentextfile(filename,1,true)
total=txt.readline
total=cint(total)
'response.write total
response.write Digital (total) '調(diào)用顯示函數(shù)
set fs=nothing
End Function
%>
然后新建一個(gè)count.txt(必須和count.asp同一級(jí)目錄),打開這個(gè)文件后在里面輸入任意數(shù)字(別太狠啦),然后在需要顯示計(jì)數(shù)器的那個(gè)頁面頂部加入
復(fù)制代碼 代碼如下:
!--#include file="count.asp"-->
最后在需要顯示計(jì)數(shù)器的地方加上代碼
復(fù)制代碼 代碼如下:
%=count_show%>
就OK了。