asp 가장 간단 하고 실 용적 인 카운터

방금 계산 기 를 찾 았 는데 사이트 의 방 문 량 이 너무 적어 서 계산 기 를 놓 으 면 좀 초라 하 다.그래서 호 는 간단 한 것 만 만 만 들 수 있 고 한 번 방문 하면 한 번 만 기록 할 수 있 는 것 으로 체면 을 유지 할 수 있다.원래 예전 에 제 가 하나 있 었 는데 답답 한 것 은 찾 지 못 했 습 니 다.인터넷 에서 SO 를 한 바퀴 돌 았 는데 드디어 해결 되 었 습 니 다.구체 적 인 프로그램 코드 는 다음 과 같 습 니 다.count.asp 의 코드 는: 

<% 
    option explicit 
  dim fs,filename,txt,content,total,counter_lenth 
  counter_lenth=1  ' ,  
  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 ' 0 
    set fs=nothing 
  end if 

  set txt=fs.OpenTextFile(filename) 
  If txt.AtEndOfStream Then 
    Application("Counter")=0 ' , Application("Counter") ( ) 
  else 
    Application("Counter")=txt.readline 
  end if 

  Application.Lock  
  Application("Counter") = Application("Counter") + 1 
  Application.UnLock 


  Function save_ '  
  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_  '  

  Function Digital ( counter )  '  
    Dim i,MyStr,sCounter 
     sCounter = CStr(counter) 
    For i = 1 To counter_lenth - Len(sCounter) 
      MyStr = MyStr & "0" 
    'MyStr = MyStr & "<IMG SRC= \0.gif>" ' ,  
    Next 
    For i = 1 To Len(sCounter) 
      MyStr = MyStr & Mid(sCounter, i, 1) 
    'MyStr = MyStr & "<IMG SRC= \" & Mid(sCounter, i, 1) & ".gif>" ' ,  
    Next 
    Digital = MyStr 
  End Function 

  Function count_show  '  
  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) '  
  set fs=nothing 
  End Function 

%>
그리고 count.txt(count.asp 와 같은 레벨 디 렉 터 리 가 필요 합 니 다)를 새로 만 들 고 이 파일 을 열 고 그 안에 임의의 숫자(너무 독 하 게 하지 마 세 요)를 입력 한 다음 계수 기 를 표시 해 야 하 는 페이지 상단 에 가입

<!--#include file="count.asp"--> 
하고 마지막 으로 계수 기 를 표시 해 야 하 는 곳 에 코드

<%=count_show%> 
를 추가 하면 됩 니 다.

좋은 웹페이지 즐겨찾기