home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 March
/
PCWorld_2001-03_cd.bin
/
Software
/
Topware
/
aspedit
/
_SETUP.1
/
counter5.asp
< prev
next >
Wrap
Text File
|
1998-07-02
|
3KB
|
90 lines
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
' Constants for FileSystemObject
Const ForReading = 1, ForWriting = 2
' Get the physical path of the counter file. Here the counter.txt is in the root
' of the web site
sPath = Server.mapPath("/counter.txt")
' Create a file system object and open the counter file for reading
Set Fs = CreateObject ("Scripting.FileSystemObject")
Set CountFile = Fs.OpenTextFile(sPath, ForReading)
' Read the two lines of the counter file, trim any spaces
sVisits = Trim(CountFile.Readline())
sVisitors = Trim(CountFile.Readline())
' Close the counter file
CountFile.Close
' Set the count of visits and visitors in Application variables
Application("Visits") = CLng(sVisits)
Application("Visitors") = CLng(sVisitors)
' Release File system object and counter file
Set Fs = Nothing
Set CountFile = Nothing
End Sub
</SCRIPT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
' Constants for FileSystemObject
Const ForReading = 1, ForWriting = 2
' Constant for write interval. Change this to suit your needs
Const cWriteInterval = 100
' Get the physical path of the counter file. Here the counter.txt is in the root of
' the web site
sPath = Server.mapPath("/counter.txt")
' Get the cookie from the visitor. The VISITORID cookie may have been set
' in which case sVisitorID will contain a value
sVisitorID = Request.Cookies("VISITORID")
' Lock the application to increment the counts
Application.Lock
' Increment the visits by 1. This happens every time a new session is created
lVisits = Application("Visits") + 1
' The number of visitors is obtained. It is incremented later in the code
lVisitors = Application("Visitors")
' Check if the VISITORID cookie exists. If it doesn't, set a new cookie with the
' value of visitor number. This cookie expires December 31, 2000.
If Len (sVisitorID) = 0 Then
lVisitors = lVisitors + 1
Response.Cookies("VISITORID") = lVisitors
Response.Cookies("VISITORID").Expires = #12/31/2000#
End If
' Write the counts into the counter file at cWriteInterval hits
If ((Application("Visits") Mod cWriteInterval) = 0) Then
' Create a file system object and open the counter file for writing
Set Fs = CreateObject("Scripting.FileSystemObject")
Set CountFile = Fs.OpenTextFile (sPath, ForWriting)
' Write the new counts into counter.txt
CountFile.Writeline(lVisits)
CountFile.WriteLine(lVisitors)
' Close the counter file
CountFile.Close
' Release File system object and counter file
Set Fs = Nothing
Set CountFile = Nothing
End If
' Set the count of visits and visitors in Application variables
Application("Visits") = lVisits
Application("Visitors") = lVisitors
' Unlock the application object
Application.Unlock
End Sub
</SCRIPT>