Creating an ASP-driven Page Counter for HTML Pages, Part 2By Greg Walker
In Part 1 we looked at what possible solutions we could employ to create a page counter that would work on both ASP pages and static HTML pages. In this part we'll examine the source code for the ASP hit counting page that does the actual work of incrementing the counter, as well as the needed HTML to display the counter (on either an ASP or HTML page).
The Source Code for
We implemented a simple counter of our own, using text files to store the individual counter values. With a little code modification you could easily use one of the ASP components as your counter, or use a database in place of the individual text files. The following is the ASP code (
HitCounter.asp) responsible for keeping count of our HTML page hits as
well as formatting the page hit counts value into digits for displaying
The source code for
HitCounter.asp has been moved from the body of this
To use a counter on one of your HTML pages simply insert the following code into your HTML page where you want your counter to show up.
To use the example code a couple of edits will need to be made:
- In the ASP file
HitCounter.aspthe value of the Constant
CounterPathwill need to be changed to reflect the path on the server where you load
HitCounter.asp. This path will also be where all your counter files will be written.
- The paths used in the
HtmlCounter.htmlfile will need to be modified to reflect the proper values, depending on the location of
HitCounter.aspon your server.
- On your server you will need to make a folder structure like the one
used for this code, if the example folder structure is not used, the
code will need to be modified to reflect any changes made. The folder
structure required for the example code is as follows:
All digit GIF files (included in the ZIP file at the end of this article)
- The following is brief descriptions of the example files:
ASP code that manages all html pages page hits.
Html code snippet to be inserted into html pages where you want your counter to show up.
Our counterlogo in gif format use this or create your own (may want to use similar dimensions)
Zip file of digits used in building counter use these, or substitute with your own.
With this general idea there are many other things you could do with ASP to make static HTML pages come alive (without having to make them into ASP pages) Please feel free to visit the site that this article was written around at http://www.huntguide.com. All 30 plus counters on this site are now using a similar version of the example code.
We are also developing a counter administration page for this customer's site to allow us to maintain and administer the counters more easily. If anyone is interested, the code for this will be posted on our site in the near future at http://www.allinthecode.com.
I work full time for a medium sized Mechanical Contractor, in their Building Automation Group as an Engineer/Programmer. I have been in this field for over 17 years. I work after hours (nights & weekends) for my wife's web design company. I am self taught, and have been learning and working with ASP for about a year. I owe alot of what I've been able to learn and accomplish using ASP, to 4Guys. I had always hoped I would someday be able to give back to such a great resource. I have thouroghly enjoyed writing this article, and hope to get the chance to write again. Thanks 4Guys!