XBM Web Page Counter


 

An open-source Windows page counter built around XBM graphics and either ASP or VBS-CGI.


This page has been read 0 times. Or reloaded that many times. Or something.

I wanted it to look like normal text. I wrote it in Visual Basic Scripting as a CGI running under the Windows Scripting Host. I then re-wrote it to run as an ASP script. It creates "xbm" graphic digits showing how many times your web page was hit. Never heard of xbm? It's a Unix-family graphic type that is supported by all modern browsers! Unfortunately, Internet Explorer is not a modern browser.

The great thing about xbm files is that they are plain-text. You can create xbm graphic files with Notepad. The other great thing (and the real reason I used xbm here) is that splicing multiple images together is a simple string processing operation. No special graphics libraries are required. You don't need a .NET server. You can get by with ordinary ASP or (if you're on a shoestring web server like Tiny or Abyss) even run the counter as a CGI using a VBS or WSF script.

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. Here is an example of the raw HTML code:

This page has been read&nbsp;<img src="http://127.0.0.1/counter.asp">&nbsp;times.
If you want leading zeros (so you'll have a fixed size graphic for faster page loading), 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 only works if the tag to reset the counter is on the page being counted. 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, but maybe you don't have a copy of Microsoft Access.


If you are curious about how things work, you can download all the scripts here.


If you don't like the idea of a graphic, I have a counter named "counter.wsf" that generates plain text. Although real text might sound easier, it's actually tougher to put it in a web page! Well, it's tough if your server won't let you use SSI or ASP. Here's a non-SSI sample:

This page has been read by&nbsp;<iframe
frameborder="0"
scrolling="no"
height="15"
width="24"
marginheight="0"
marginwidth="0"
src="http://127.0.0.1/counter.wsf?digits=3"
></iframe>&nbsp;people.

The height is fixed at 15 (empirical testing!), and the width is 8 times the number of digits. Unfortunately, the digits, height, and width must be specified. This "wsf" counter also uses the same count database as the "asp" and "vbs" counters, so you can switch between them without affecting your count (other than incrementing your count every time you test it!).


More than you want to know:

If you're a programmer, it should be fairly easy for you to splice on a "white list" of sites allowed to use the counter. 

Permissions... You'll need to set your file permissions up to allow the IUSR account to have write permissions on your mdb file. You may also want to create an empty "ldb" file and give the IUSR account write (but not delete) permissions on it as well. That way the database engine will be able to lock the database.

Want to know how to create your own XBM character font files? You have to understand hex and binary (ask someone if you don't). Just create a left-right swapped mirror image of what you want in a grid. Here is an example showing a picture of the digit "7":

And here is how you list the hex values you figured out in an xbm file:

#define xmosaic_width 8
#define xmosaic_height 11
static char xmosaic_bits[] = {
0x7E,
0x41,
0x40,
0x20,
0x20,
0x20,
0x10,
0x10,
0x10,
0x08,
0x08,
};

Just write all that text down in Notepad, save it as "7.xbm" (with the quotes!), and you've created an itty-bitty picture. Truthfully, each value doesn't have to be on it's own line to be an xbm file. It just has to be on a separate line so the scripts can read the separate values. 



Lost? Look at the site map.

Bad links? Questions? Send me mail.

Google
Yahoo
Ask Jeeves