9:18 am Wednesday, August 20, 2008


  Navigation
  Help?
Contact Aaron for all inquiries.
 

  News

ASP Inline Calendar 3.9 Beta 1
ASP Games
ASP Inline Corporate Calendar 3.8 BETA 1 Demo
Calendar Updates
 

A Better World By Design
 
  Hit Counter Tutorial
AaronOutpost : ASP / Tutorials / Counters / Hit Counter

Graphical Hit Counter Tutorial
By: Aaron B. Copyright AaronOutpost.com

Counters Tutorial
  1. Create a Text Hit Counter

  2. Create a Graphic Hit Counter

  3. Create a Text or Graphic Session Hit Counter

  4. Create an Active User Hit Counter using global.asa

Welcome to Part 2 of 4 Counter Tutorials. We are now going to take the counter from Step1: Create a Text Hit Counter and use graphics to display the hit count.

Create Number Images
    So, open your favorite photo editor and make some number files. Make as many test images as you want. Then create each individual number image. Then name them images the number which is in the picture. You can use any extension: gif, jpg, etc... This is the fun part and can be changed easily at anytime. But, it's your own design and you can make it fit your own site. I named my files: 0.gif ; 1.gif ; 2.gif ; etc... I then placed the images files into a folder in the directory at which I am going to place my Hit Counter Script.

 

 

Here we use a "For / Next" loop to display the graphics. Using the VBScript "Len" function we will get the length of the number in the text file. It will count how many numbers there are. 

1000 has 4 numbers        :          500 has 3 number          :          98542 has 5 numbers

First we have to define the loop count to be used. We want to go from 1 to the length of the number in the test file.

'----------------------------------------------------------
'Display the hit count as images using loop

'-----------------------------------------------------------

For LoopCount = 1 to Len(NumberVisitors) %>


I have it use the specific number .gif file to display by using the "Mid" function. I went on and included the ALT text for the image file. So if image does not display then the text will. Something that is wise for you to do with all images. Then it loops to the next number.

<img src="counter_images/<%= Mid(NumberVisitors, LoopCount, 1) %>.gif" alt="<%= Mid(NumberVisitors, LoopCount, 1) %>">

 

<% Next %>

 

 

Finally this finished project should look something like this! Make sure it is saved in .asp format as mentioned before and must be run on an ASP2 enabled server.

Don't want the count to only count each user once?
Visit Part 3
Create a Text or Graphic Session Hit Counter

<html>

<head>

<title>Hit Counter</title>

</head>

<body bgcolor="white" text="black">

<div align="center">

<h3>Hit Counter</h3>

 

<%

 

Dim FileSystemObject, TextStreamObject, FileObject, NumberVisitors, LoopCount

 

'-----------------------------------------------------------
' Get and open hit count file

'-----------------------------------------------------------

Set FileSystemObject= Server.CreateObject("Scripting.FileSystemObject")

Set FileObject = FileSystemObject.GetFile(Server.MapPath("hit_counter.txt"))

Set TextStreamObject = FileObject.OpenAsTextStream

 

'-----------------------------------------------------------

' Increment count

'-----------------------------------------------------------

NumberVisitors = CLng(TextStreamObject.ReadAll)

NumberVisitors = NumberVisitors + 1

 

Set TextStreamObject = FileSystemObject.CreateTextFile(Server.MapPath("hit_counter.txt"))


TextStreamObject
.Write CStr(NumberVisitors)

 

 

Set FileSystemObject= Nothing

Set TextStreamObject = Nothing

Set FileObject = Nothing

 

'-----------------------------------------------------------
'Display the hit count as text

'-----------------------------------------------------------

%>

Text Version of Count <br>
<%=
NumberVisitors %>

<br>

<br>


'----------------------------------------------------------
'Display the hit count as images using loop

'-----------------------------------------------------------

For LoopCount = 1 to Len(NumberVisitors) %>

 

 

<img src="counter_images/<%= Mid(NumberVisitors, LoopCount, 1) %>.gif" alt="<%= Mid(NumberVisitors, LoopCount, 1) %>">

 

<% Next %>

 

<br>

</div>

</body>

</html>


AaronOutpost : ASP / Tutorials / Counters / Graphical Hit Counter

Aaron Outpost West Virginia, USA A Mark of _-Squire-_ Creations Inc.  CopyrightŠ 2005 All Rights Reserved