#!/usr/bin/perl
use GD;
# Basic Web Hit Counter
# By Peter Brayman
#
# Uses a Single Text File to store the hits.
# Returns a Dynamic Image of the number of hits
#
# Called via
#
# Program is provided AS-IS, Peter Brayman is not reposinsible for any problems
# or loss of data that may arise from this program's use. Technical support is
# not provided, this program requires the GD perl module and perl to function.
# Data File (for hits)
$data = "simplecount1.txt";
#Total Number of Places
$places = "9";
#Text Coloe
$tcolor = "white";
# --- DONT EDIT BELOW HERE ---- #
# Read the current hits
open(CURHITS,"<$data");
flock(CURHITS, LOCK_SH);
$curhits = ;
close(CURHITS);
chomp($curhits);
if ($curhits == "0") { $curhits = $start - 1; }
# Add 1 to the current hits and write it
open(NEWHITS,">$data");
flock(NEWHITS, LOCK_EX);
print NEWHITS $curhits + 1;
close(NEWHITS);
# Count the Numbers; Add some zeros
$_ = $curhits;
$w = tr/0-9//;
$p = "";
$pad = 0;
unless ($w > $places) {
$pad = $places - $w;
for($i=0;$i<$pad;$i++) {
$p .= "0";
}
}
$curhits = $p . $curhits;
$width = (($w + $pad) * 10) + 5;
$height = 16;
#create a new image
$im = new GD::Image($width,$height);
$purple = $im->colorAllocate(255,0,255);
$black = $im->colorAllocate(0,0,0);
$white = $im->colorAllocate(255,255,255);
# set purple as our clip color for transparency
$im->transparent($purple);
$im->interlaced('true');
# Draw the hits
$im->string(gdGiantFont,5,1,$curhits,$$tcolor);
print "Content-type: image/png\n\n";
binmode STDOUT;
print $im->png;
exit;