:
: "alfa_beveren" wrote:
: : How to make a simple Hit Counter ?
:
: <%
:
: ' Author: Roland Hall
: ' Subject: ASP Hit Counter
: ' Date: Feb. 04, 2004
: ' NS: msnews.microsoft.com
: ' NG: microsoft.public.inetserver.asp.general
: 'Filename: hitcounter.asp
: ' Modify: sFile = "drive
ath\hitcounter.txt" - IUSR must have change
: rights
: ' Use: Include file in any ASP file to display current hit count
: ' Note: File is automatically created if it does not exists and value
set
: to 0
:
: Sub writeFile(strFile,strHits)
: Const ForWriting=2
: Dim oFS, oFSFile
: Set oFS = Server.CreateObject("Scripting.FileSystemObject")
: Set oFSFile = oFS.OpenTextFile(strFile,ForWriting,True)
: oFSFile.Write(strHits)
: oFSFile.Close
: Set oFSFile = Nothing
: Set oFS = Nothing
: End Sub
:
: Function readFile(strFile)
: Dim oFS, strHits, oTextStream
: Set oFS = Server.CreateObject("Scripting.FileSystemObject")
: If oFS.FileExists(strFile) = True Then
: Set oTextStream = oFS.OpenTextFile(strFile,1)
: strHits = oTextStream.ReadAll
: oTextStream.Close
: Set oTextStream = nothing
: End if
: Set oFS = nothing
: ReadFile = strHits
: End Function
:
: Sub getCount()
: Dim sfile, hitCount
: sFile = "drive
ath\hitcounter.txt"
: hitCount = readFile(sFile)
: if hitCount = "" Then
: writeFile sFile, "0"
: else
: writeFile sFile, hitCount + 1
: end if
: Response.Write(hitCount)
: End Sub
:
: getCount
: %>
:
: This is my test page:
:
: <%@ Language=VBScript %>
: <%
: Option Explicit
: Response.Buffer = True
: %>
: <html>
: <head>
: <title>Hit Counter</title>
: <script type="text/javascript">
: function cMsg(id, x) {
: var IE = document.all;
: var DOM = document.getElementById && !document.all;
: strX = 0;
: if(IE) {
: if(x == 'center') {
: document.all[id].style.width='100%';
: document.all[id].style.textAlign='center';
: } else {
: document.all[id].style.left = x;
: }
: }
: if(DOM) {
: if(x == 'center') {
: document.getElementById(id).style.width='100%';
: document.getElementById(id).style.textAlign='center';
: } else {
: document.getElementById(id).style.left = x;
: }
: }
: }
: </script>
: </head>
: <body onload="cMsg('hits', 'center')">
: <div id=hits style="position: absolute; top: 35px; font: normal 8pt
: serif"><!--#include virtual="/lab/hitcounter.asp"--> people can't be
: wrong!</div>
: </body>
: </html>
:
: It works in all of the latest of IE, Mozilla and Opera.
You can see it working here:
http://kiddanger.com/lab/hitcount.asp
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp