<?php
#---------------------------#
#--      counter.php      --#
#---------------------------#

session_start();

mysql_connect("localhost", "...", "...");
mysql_select_db("...");

if(!isset($_SESSION['updated'])) {
      $sql = "UPDATE `counter` SET `hits` = (hits + 1)";
      $res = mysql_query($sql);
	
      if($res == true)
            $_SESSION['updated'] = "jup";
}

	
$sql = "SELECT `hits` FROM `counter`";
$res = mysql_query($sql);
$num = mysql_result($res, 0);

while(strlen($num) < 8 ) {
      $num = '0'.$num;
}

echo '<img src="image.php?num='.$num.'" alt="'.$num.' Hits" />';
?>


================================


<?php
#-------------------------#
#--     image.php       --#
#-------------------------#

$num   = isset($_GET['num']) ? $_GET['num'] : '';
$image = imagecreatefromjpeg("counter.jpg");
$color = imagecolorallocate($image, 80, 100, 120);
imagettftext($image, 12, 0, 10, 40, $color, 'verdana.ttf', $num);

header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);

?>


================================


SQL:

CREATE TABLE `counter` (
  `hits` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`hits`)
) TYPE=MyISAM;

INSERT INTO `counter` VALUES (0);
