剛才找一個計數器,由於網站的訪問量太少,放個計數器在那裡確實有點寒酸了,於是呼只能搞一個簡單點的,可以訪問一次就記錄一次的來撐撐門面先。本來以前我有一個,但是鬱悶的是居然找不到了,在網上SO了一圈,總算是搞定了,具體程序代碼如下。
count.asp的代碼為:
複製代碼代碼如下:
<%
optionexplicit
dimfs,filename,txt,content,total,counter_lenth
counter_lenth=1'設置顯示數據的最小長度,如果小於實際長度則以實際長度為準
setfs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
ifnotfs.FileExists(filename)then
fs.CreateTextFilefilename,True,True
settxt=fs.OpenTextFile(filename,2,true)
txt.write0'如不存在保存數據的文件則創建新文件並寫入數據0
setfs=nothing
endif
settxt=fs.OpenTextFile(filename)
Iftxt.AtEndOfStreamThen
Application("Counter")=0'如果文件中沒有數據,則初始化Application("Counter")的值(為了容錯)
else
Application("Counter")=txt.readline
endif
Application.Lock
Application("Counter")=Application("Counter")+1
Application.UnLock
Functionsave_'保存計數函數
setfs=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("count.txt")
content=Application("Counter")
settxt=fs.OpenTextFile(filename,2,true)
txt.writecontent
setfs=nothing
EndFunction
save_'調用保存函數保存數據
FunctionDigital(counter)'顯示數據函數
Dimi,MyStr,sCounter
sCounter=CStr(counter)
Fori=1Tocounter_lenth-Len(sCounter)
MyStr=MyStr&"0"
'MyStr=MyStr&"<IMGSRC=改成你自己的圖片存放的相對目錄/0.gif>"'如有圖片,可用此語句調用
Next