Notelay home page
Did you know?
To make one kilo of honey bees have to visit 4 million flowers, travelling a distance equal to 4 times around the earth.
Helllooo

A very simple to use ASP Hit Counter

Thu, Jan 17 2007

A simple to use ASP home made HIT COUNTER it measures unique visitors and page views of your site, it's very simple to setup and use. So lets get to business:

1 Setup

It's very easy to setup there are two ways to do it. The first way is to copy and paste the script below in the top of every asp page.

The second way is to copy the script below and save it in a file for example counter.inc then in the top of your asp pages paste this <!--#include virtual="$path/counter.inc"--> $path stands for the path where you saved your file.

<% Dim Path Path = Server.MapPath("/counter.txt") Dim PageViews, UniqueVisitors Dim FSO, FO Set FSO = Server.CreateObject("Scripting.FileSystemObject") If ( FSO.FileExists( Path ) ) Then Set FO = FSO.OpenTextFile(Path, 1, False) PageViews = cInt(FO.readLine) UniqueVisitors = cInt(FO.readLine) FO.close If ( Session("Returning") <> True ) Then UniqueVisitors = UniqueVisitors + 1 Session("Returning") = True End if PageViews = PageViews + 1 Set FO = FSO.OpenTextFile(Path , 2, False) FO.WriteLine(PageViews) FO.WriteLine(UniqueVisitors) FO.Close Set FO = Nothing Else Dim NewFile Set NewFile = FSO.CreateTextFile(Path, True) NewFile.WriteLine("1") NewFile.WriteLine("1") NewFile.Close Set NewFile = Nothing PageViews = 1 UniqueVisitors = 1 Session("Returning") = True End if Set FSO = Nothing %> 2 Use

Now all we need to do is show the results on the pages, and we are going to do that with the next code:

<strong> This site is visited: [<%= UniqueVisitors %>] times. <br /> And guests visited: [<%= PageViews %>] pages. </strong>

And the result looks like this:

This site is visited: [5] times.
And guests visited: [25] pages.

Warning: You must have appropriate permissions on the server to use this counter.



Digg reddit.com del.icio.us Technorati StumbleUpon Blue Dot Netscape ma.gnolia BlinkList Blogmarks Furl Spurl Google Bookmarks Yahoo Windows Live Favorites

To the top New comment:
Name:
Comment:
 

Notelay survey

Do you believe in Love at first sight?

vote No way! (20.3%)
20.3
vote That's the only love I believe (16.8%)
16.8
vote If the boy/girl is really good looking (17%)
17
vote Sometimes if the surrounding's romantic (15.3%)
15.3
vote Yes, It always happen to me (15.7%)
15.7
vote I never fall in love (14.9%)
14.9

Quote of the day

Dream is destiny!
From the movie "Waking life"

Advertisements

Startingggg

Associates

© 2006 Notelay | All Rights Reserved.