佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > asp最簡(jiǎn)單最實(shí)用的計(jì)數(shù)器

asp最簡(jiǎn)單最實(shí)用的計(jì)數(shù)器

熱門標(biāo)簽:Mysql連接數(shù)設(shè)置 服務(wù)器配置 銀行業(yè)務(wù) 阿里云 團(tuán)購(gòu)網(wǎng)站 Linux服務(wù)器 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 電子圍欄
剛才找一個(gè)計(jì)數(shù)器,由于網(wǎng)站的訪問(wèn)量太少,放個(gè)計(jì)數(shù)器在那里確實(shí)有點(diǎn)寒酸了,于是呼只能搞一個(gè)簡(jiǎn)單點(diǎn)的,可以訪問(wèn)一次就記錄一次的來(lái)?yè)螕伍T面先。本來(lái)以前我有一個(gè),但是郁悶的是居然找不到了,在網(wǎng)上SO了一圈,總算是搞定了,具體程序代碼如下。
  count.asp的代碼為: 

復(fù)制代碼 代碼如下:


    option explicit 
  dim fs,filename,txt,content,total,counter_lenth 
  counter_lenth=1  '設(shè)置顯示數(shù)據(jù)的最小長(zhǎng)度,如果小于實(shí)際長(zhǎng)度則以實(shí)際長(zhǎng)度為準(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)建新文件并寫(xiě)入數(shù)據(jù)0 
    set fs=nothing 
  end if 

  set txt=fs.OpenTextFile(filename) 
  If txt.AtEndOfStream Then 
    Application("Counter")=0 '如果文件中沒(méi)有數(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=改成你自己的圖片存放的相對(duì)目錄\0.gif>" '如有圖片,可用此語(yǔ)句調(diào)用 
    Next 
    For i = 1 To Len(sCounter) 
      MyStr = MyStr  Mid(sCounter, i, 1) 
    'MyStr = MyStr  "IMG SRC=改成你自己的圖片存放的相對(duì)目錄\"  Mid(sCounter, i, 1)  ".gif>" '如有圖片,可用此語(yǔ)句調(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í)目錄),打開(kāi)這個(gè)文件后在里面輸入任意數(shù)字(別太狠啦),然后在需要顯示計(jì)數(shù)器的那個(gè)頁(yè)面頂部加入
復(fù)制代碼 代碼如下:

!--#include file="count.asp"--> 


最后在需要顯示計(jì)數(shù)器的地方加上代碼
復(fù)制代碼 代碼如下:

%=count_show%> 


就OK了。

標(biāo)簽:棗莊 江蘇 大理 衡水 衢州 萍鄉(xiāng) 蚌埠 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp最簡(jiǎn)單最實(shí)用的計(jì)數(shù)器》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    凤凰县| 手游| 谢通门县| 天门市| 长春市| 桐城市| 本溪市| 富蕴县| 乐山市| 衡东县| 柳林县| 潮安县| 抚宁县| 乐陵市| 时尚| 吉安市| 平武县| 酒泉市| 乌海市| 浦东新区| 莫力| 三江| 镇坪县| 哈巴河县| 临漳县| 天峻县| 安宁市| 大冶市| 黑龙江省| 宁波市| 二手房| 桂林市| 乌审旗| 奉节县| 广西| 塔河县| 邓州市| 英吉沙县| 洪泽县| 唐海县| 出国|