473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Hit Counter

How to make a simple Hit Counter ?

I am old VB Programmer, trying to learn ASP...

al**********@hotmail.com
Jul 19 '05 #1
8 1960
You nees to use an Application or session variable. In Global.asa add
the counter to the On_Start function.
On Wed, 4 Feb 2004 15:54:00 +0100, "alfa_beveren"
<al**********@hotmail.com> wrote:
How to make a simple Hit Counter ?

I am old VB Programmer, trying to learn ASP...

al**********@hotmail.com


Jul 19 '05 #2
Hi,
Create an ASCII file
Use the FSO Object to open the file, read the number written there.
Replace it with the num+1 and display the num+1.

* You can use a database instead

Roy.

"alfa_beveren" <al**********@hotmail.com> wrote in message
news:BI******************@news2.e.nsc.no...
How to make a simple Hit Counter ?

I am old VB Programmer, trying to learn ASP...

al**********@hotmail.com

Jul 19 '05 #3
wrote on 04 feb 2004 in microsoft.public.inetserver.asp.general:
On Wed, 4 Feb 2004 15:54:00 +0100, "alfa_beveren"
<al**********@hotmail.com> wrote:
How to make a simple Hit Counter ?

I am old VB Programmer, trying to learn ASP...

You nees to use an Application or session variable. In Global.asa add
the counter to the On_Start function.


============================
1
A session variable will not help you.
It will only count the hits you yourself made in one session.

=============================
2
<%
if application("MypageHits")="" then
application("MypageHits")=1
else
application("MypageHits")=application("MypageHits" )+1
end if
response.write application("MypageHits") & "Hits<br>"
%>

This will count the hits till the server is reset.
Not a good option either.

==============================
2
Use a database or a textfile and
"read increment write" the number stored there.

for this you have to read up on databases or look here:

<http://www.4guysfromrolla.com/webtech/041801-1.shtml>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #4
"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:path\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:path\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='cente r';
} 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.

--
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
Jul 19 '05 #5
<<
How to make a simple Hit Counter ?

I am old VB Programmer, trying to learn ASP...


Here's something that doesn't even require any ASP knowledge:

Free tracker from eXTReMe digital
http://www.extreme-dm.com

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #6
"Roland Hall" wrote:
: "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:path\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:path\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='cente r';
: } 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
Jul 19 '05 #7
My company is BLOCKING this site http://www.extreme-dm.com/ why?
"Bullschmidt" <pa**@bullschmidt.com-nospam> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
<<
How to make a simple Hit Counter ?

I am old VB Programmer, trying to learn ASP...


Here's something that doesn't even require any ASP knowledge:

Free tracker from eXTReMe digital
http://www.extreme-dm.com

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #8
"Girish" wrote:
: My company is BLOCKING this site http://www.extreme-dm.com/ why?

Perhaps their marketing involves UCE but to know for sure, ask your IT
department.

--
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
Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shane | last post by:
:) I am following a tutorial for php (hudzilla.org) absolutely loving it however I am having trouble with the counter example <?php // your content here... $filename = 'counter.txt'; // our...
16
by: Paul Rubin | last post by:
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. ...
7
by: JellyON | last post by:
Hi. Is there a way to delay a call to a page counter (ie. call to a server script from an IMG tag) for the purpose to not lock the page loading awaiting counter be displayed. Maybe a...
0
by: Earl Anderson | last post by:
KB Article Q140908 provided the following function to create an Auto Incrementing Counter: Function Next_Custom_Counter () On Error GoTo Next_Custom_Counter_Err Dim MyDB As Database Dim...
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
0
by: Trevor L. | last post by:
I decide to put a custom Hit Counter on my page (below). Then I won't be reliant on the standard FrontPage one which uses webbots. It is called by <b>Hit Counter: </b><!--#include...
12
by: devospice | last post by:
Hi, I'm trying to create a download counter for individual files on a web site and I'm not sure how to do this. Right now I'm using Webalizer to just read the log files and see how many times...
5
by: jasonchan | last post by:
How would you set up a counter in javascript that goes from 5 to 0 This is what i have so far and it is not displaying in the div container "counter" for some reason... <!DOCTYPE html PUBLIC...
3
blackstormdragon
by: blackstormdragon | last post by:
Here were our instructions: "My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to...
2
by: gumbercules | last post by:
I am designing a site that is regulary updated with new podcasts. I would like to be able to have a counter next to each podcast showing how many hits/listens/plays/views each particular podcast has...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.