[12210]  daemon@ATHENA.MIT.EDU (Matthew Gray) Webmaster 07/12/95 02:02 (76 lines)
Subject: Counters...
Date: Wed, 12 Jul 1995 02:02:09 -0400 (EDT)
From: Matthew Gray <mkgray@netgen.com>
To: webmaster@MIT.EDU

It seems like there's been a number of questions about counters for 
pages, and if we think people should be able to use them, I've included 
one I wrote which allows multiple people and multiple pages to use the 
same counter...

You do something like: <img src="/cgi-bin/counter/mkgray-home-page">

It outputs a bitmap containing the number of hits to the page.
If anyone wants to install this, feel free.  References to /tmp/counterdb 
should probably be changed to some other file...
Thoughts?

					...Mkgray

#!/usr/bin/perl

@numbs = ( "0xff","0xff","0xff","0xc3","0x99","0x99","0x99","0x99",
	   "0x99","0x99","0x99","0x99","0xc3","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xcf","0xc7","0xcf","0xcf","0xcf",
	   "0xcf","0xcf","0xcf","0xcf","0xcf","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xc3","0x99","0x9f","0x9f","0xcf",
	   "0xe7","0xf3","0xf9","0xf9","0x81","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xc3","0x99","0x9f","0x9f","0xc7",
	   "0x9f","0x9f","0x9f","0x99","0xc3","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xcf","0xcf","0xc7","0xc7","0xcb",
	   "0xcb","0xcd","0x81","0xcf","0x87","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0x81","0xf9","0xf9","0xf9","0xc1",
	   "0x9f","0x9f","0x9f","0x99","0xc3","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xc7","0xf3","0xf9","0xf9","0xc1",
	   "0x99","0x99","0x99","0x99","0xc3","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0x81","0x99","0x9f","0x9f","0xcf",
	   "0xcf","0xe7","0xe7","0xf3","0xf3","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xc3","0x99","0x99","0x99","0xc3",
	   "0x99","0x99","0x99","0x99","0xc3","0xff","0xff","0xff",
	   "0xff","0xff","0xff","0xc3","0x99","0x99","0x99","0x99",
	   "0x83","0x9f","0x9f","0xcf","0xe3","0xff","0xff","0xff");


sub bitmap {
    local($num) = @_;	
    @digits = split(//, $num);
    $wid = length($num)*8;	
    print("#define counter_width $wid\n");
    print("#define counter_height 16\n");
    print("static char counter_bits[] = {\n");
    for $row (0..15){
	for $col (0..(length($num)-1)){
	    print("\"");
	    print($numbs[$row+($digits[$col]*16)]);
	    print("\", ");
	}
    }
    print("};\n");
}

$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;

$key = $ENV{'PATH_INFO'};
open(LOCK, ">/tmp/counter.lock");
flock(LOCK, $LOCK_EX);
dbmopen(counterdb, "/tmp/counterdb", 0777);
$counterdb{$key}++;
$val = $counterdb{$key};
dbmclose(counterdb);
flock(LOCK, $LOCK_UN);

print("Content-type: image/x-xbitmap\n\n");

&bitmap($val);
--[12210]--

