BMP Web Page Counter
Released to Public Domain by Eric Phelps
http://www.ericphelps.com
May be used, distributed, and modified with no restrictions.

--------------------------------------------------------------------------------

Usage:
Here are the tags you need to insert. Just define an image and use this 
(corrected to your actual script 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. If you want to see it in action, click here to reset 
the counter to 56 or click here to reset the counter to 137. Sure, you could 
also directly edit the database to reset a counter, but maybe you don't have a 
copy of Microsoft Access.

--------------------------------------------------------------------------------

Permissions:
You'll need to set your file permissions up to allow the IUSR account to have 
write permissions on your "counter.mdb" file. You also need to create an empty 
"counter.ldb" file and give the IUSR account write (but not delete) permissions 
on it as well.

--------------------------------------------------------------------------------

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 anything else on this 
sample code because I have no idea what directory structure you have on your 
server! The counter will try to create the database file if it doesn't exist, 
but it will fail because of the permissions problem mentioned above (It will 
succeed if your server runs on Win9x which tells you how old this code base is).

--------------------------------------------------------------------------------

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 - 0
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

The first line is used for the background, and the second line is used for the 
font color. Nothing else is used -- but all 16 lines have to be there! If you 
decided you wanted a yellow background and red text, you could just shuffle the 
lines around like this:

strBuffer = strBuffer & ChrB(0) & ChrB(255) & ChrB(255) & ChrB(0) 'Yellow - 7
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

--------------------------------------------------------------------------------

Fonts:
If you're interested in making your own, the actual counter digits are stored 
in the constant "IMAGE_DATA" or the variable "strImageData" (depending on which 
counter you have). Start out with a simple screen capture of the numbers 0 
through 9, then use a graphics program to chop them into separate 
identically-sized images. Then use the IrfanView program to save each digit as 
a PBM file with "Ascii encoding".  If you look at the resulting pbm file with 
WordPad, you get something like this:

P1
# 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 

Delete the first three lines, unwrap the text, remove all the spaces, and 
paste the ones and zeros into the IMAGE_DATA constant (or strImageData 
variable). Then do it again until all ten numbers have been processed into 
one massive string.

Why not have separate graphics files? Because it's easier to generate a new 
graphic by directly going to the needed bits in a single string than it would 
be to have to read, parse, and join ten separate graphic files every time. I 
say do the hard work once and let the script (and your server) take it easy.

--------------------------------------------------------------------------------

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.