BMP Web Page Counter |
This page has been read times. Or reloaded that many times. Or something.
The number you just read above is a dynamically-created single image (not several separate images) created without using any external libraries. That means only one image link on your web page and no DLL or OCX files. Nothing but pure VBS-ASP code. Just what you need on a hosted site that won't let you install graphics libraries! BMP works as an inline image in all modern browsers (Firefox, Mozilla, and IE4/5/6) and the image file sizes are so small compression isn't needed (anything small enough to fit in a single ethernet packet doesn't need compression).
The counter has font/digit information embedded in the ASP code. Changing colors and adding borders is fairly straightforward (directions are on this page). Click one of the below graphics to download the related counter:
Usage:
Here are the tags you need to insert. Just define an image and
use this (corrected to your actual counter location) as the image
source:
http://127.0.0.1/counter.asp
Be sure your html editor doesn't put image size in the tag! Remember, the image width changes as the number of digits increases.
If you want to specify the number of digits (forcing leading zeros so you'll have a fixed size graphic), try something like this:http://127.0.0.1/counter.asp?digits=4
If you need to reset the counter to a particular value (back to zero or up to a high fake value), try putting this in your page as a tag and hitting it:http://127.0.0.1/counter.asp?count=0
This counter can only be reset from the page it counts, so there is no need to bother with user accounts or passwords or other foolishness. If you want to reset the counter, put a reset link on your page and remove the reset link after you use it. Simple. Sure, you could also directly edit the database to reset a counter, but maybe you don't have a copy of Microsoft Access.
Installation:
Put the "counter.asp", "counter.mdb", and "counter.ldb" file all
together in the same folder somewhere on your Windows server. You'll
need to set your file permissions up to
allow the IUSR account to have write permissions on your "counter.mdb"
file. Give the
IUSR account
write (but not delete) permissions on the zero-byte "counter.ldb" file.
Database
Location:
The counter ASP code assumes you'll have a "counter.mdb" in
the
same directory. Feel free to
change the code if you want. I couldn't use any other
directory on
this
sample code because I have no idea what directory structure you have on
your server! The counter will try to create the MDB file
if
it doesn't exist, but it will fail because it won't have write
permission... Unless you're running on Win9x in which case the
counter will succeed in creating the .MDB file because Win9x has no
security at all!
Colors:
It's easy to change the colors to anything you
want. In the ASP code in the ArrayToBMP function, you'll see code like
this:
strBuffer = strBuffer & ChrB(255) & ChrB(255) & ChrB(255) & ChrB(0) 'White - 0The comments at the end of each line reminds me what colors and palette order things are in. The first line is used for the background, and the second line is used for the font color. On the black-and-white counters, nothing else is used -- but all 16 lines have to be there because I generate 16-color bitmaps! If you decided you wanted a yellow background and red text, you could directly edit the values for the appropriate lines or just shuffle the lines around like this:
strBuffer = strBuffer & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) 'Black - 1
strBuffer = strBuffer & ChrB(0) & ChrB(0) & ChrB(255) & ChrB(0) 'Red - 2
strBuffer = strBuffer & ChrB(0) & ChrB(255) & ChrB(0) & ChrB(0) 'Green - 3
strBuffer = strBuffer & ChrB(255) & ChrB(0) & ChrB(0) & ChrB(0) 'Blue - 4
strBuffer = strBuffer & ChrB(255) & ChrB(255) & ChrB(0) & ChrB(0) 'Cyan - 5
strBuffer = strBuffer & ChrB(255) & ChrB(0) & ChrB(255) & ChrB(0) 'Magenta - 6
strBuffer = strBuffer & ChrB(0) & ChrB(255) & ChrB(255) & ChrB(0) 'Yellow - 7
strBuffer = strBuffer & ChrB(192) & ChrB(192) & ChrB(192) & ChrB(0) 'Light Gray - 8
strBuffer = strBuffer & ChrB(128) & ChrB(128) & ChrB(128) & ChrB(0) 'Dark Gray - 9
strBuffer = strBuffer & ChrB(0) & ChrB(0) & ChrB(128) & ChrB(0) 'Dark Red - 10
strBuffer = strBuffer & ChrB(0) & ChrB(128) & ChrB(0) & ChrB(0) 'Dark Green - 11
strBuffer = strBuffer & ChrB(128) & ChrB(0) & ChrB(0) & ChrB(0) 'Dark Blue - 12
strBuffer = strBuffer & ChrB(128) & ChrB(128) & ChrB(0) & ChrB(0) 'Dark Cyan - 13
strBuffer = strBuffer & ChrB(128) & ChrB(0) & ChrB(128) & ChrB(0) 'Dark Magenta - 14
strBuffer = strBuffer & ChrB(0) & ChrB(128) & ChrB(128) & ChrB(0) 'Dark Yellow - 15
strBuffer = strBuffer & ChrB(0) & ChrB(255) & ChrB(255) & ChrB(0) 'Yellow - 7In addition to changing colors, you can wrap a border around your counter using tables or CSS in your web page:
strBuffer = strBuffer & ChrB(0) & ChrB(0) & ChrB(255) & ChrB(0) 'Red - 2
strBuffer = strBuffer & ChrB(255) & ChrB(255) & ChrB(255) & ChrB(0) 'White - 0
strBuffer = strBuffer & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) 'Black - 1
strBuffer = strBuffer & ChrB(0) & ChrB(255) & ChrB(0) & ChrB(0) 'Green - 3
strBuffer = strBuffer & ChrB(255) & ChrB(0) & ChrB(0) & ChrB(0) 'Blue - 4
strBuffer = strBuffer & ChrB(255) & ChrB(255) & ChrB(0) & ChrB(0) 'Cyan - 5
strBuffer = strBuffer & ChrB(255) & ChrB(0) & ChrB(255) & ChrB(0) 'Magenta - 6
strBuffer = strBuffer & ChrB(192) & ChrB(192) & ChrB(192) & ChrB(0) 'Light Gray - 8
strBuffer = strBuffer & ChrB(128) & ChrB(128) & ChrB(128) & ChrB(0) 'Dark Gray - 9
strBuffer = strBuffer & ChrB(0) & ChrB(0) & ChrB(128) & ChrB(0) 'Dark Red - 10
strBuffer = strBuffer & ChrB(0) & ChrB(128) & ChrB(0) & ChrB(0) 'Dark Green - 11
strBuffer = strBuffer & ChrB(128) & ChrB(0) & ChrB(0) & ChrB(0) 'Dark Blue - 12
strBuffer = strBuffer & ChrB(128) & ChrB(128) & ChrB(0) & ChrB(0) 'Dark Cyan - 13
strBuffer = strBuffer & ChrB(128) & ChrB(0) & ChrB(128) & ChrB(0) 'Dark Magenta - 14
strBuffer = strBuffer & ChrB(0) & ChrB(128) & ChrB(128) & ChrB(0) 'Dark Yellow - 15
|
<table
border="3" cellpadding="0" cellspacing="0"> <tr><td><img src="http://127.0.0.1/counter.asp"></td></tr> </table> |
|
<div
style="border: medium solid gray;"> <img src="http://127.0.0.1/counter.asp"> </div> |
P1Delete the first three lines, unwrap the text, remove all the spaces, and paste the ones and zeros into the strImageData variable. Start with zero and keep pasting data into the strImageData variable until you get through number nine. Change the "FONT_HEIGHT" and "FONT_WIDTH" constants to show the actual height and width of your individual characters and you're done.
# Created by IrfanView
8 11
0 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0
0 0 0 1 0 0 0 0
Modifications:
If you're an ASP programmer, it should be
fairly easy for you to modify this code to use the HTTP "referer" to
check a "white list" of sites allowed to use
the counter. You can also change this from a hit counter to a unique
visit counter by adding a bit of session code. No, I'm not
going to provide sample code to do either of these tasks.
Lost? Look at the site map.
Bad links? Questions? Send me mail.