Skip navigation.
Home

Graphical hitcounter

This is a very simplistic hit counter. You include it on your page via an <img src="http://riceball.com/hitcounter/hit.php?id=1"> tag. The only "security" feature it has is checking that we don't increment on a hit from the same IP address twice in a row.

It's useless for busy sites, because repeated pageviews will clear the last ip address. I wrote it specifically for an ebay use. I didn't log all IPs or give out cookies because I suspected that those are against ebay policy.

To create a new counter, change the value of the id. The image should come up with the value "1" for starters. If not, you probably have another user's counter. Choose a diffent number.

Warning - this service may stop operating at any time.

<?php

$id = $_GET['id'];
if (! $id)
        $id = '0';

$lastip = $_SERVER['REMOTE_ADDR'];

$insert = "INSERT INTO hitcounter (id,count, lastip) VALUES ($id, 1, '$lastip')";
$update = "UPDATE hitcounter SET count=(count+1), lastip='$lastip' WHERE lastip<>'$lastip'";
$select = "SELECT count FROM hitcounter WHERE id=$id";

$link = mysql_connect( 'localhost:3306', 'riceballcom', 'ginchy' );
mysql_select_db( 'riceball_com', $link );

$res = mysql_query( $insert, $link );
if (!$res)
{
        $res = mysql_query( $update, $link );
}

$res = mysql_query( $select, $link );
$row = mysql_fetch_array( $res );
$count = $row[0];

$img = imagecreate( 100, 24 );
$background = imagecolorallocate( $img, 128, 128, 128 );
$text = imagecolorallocate( $img, 255, 255, 255 );

imagestring( $img, 5, 5, 3, "$count", $text );

header( 'Content-type: image/gif' );
imagegif( $img );
exit;

?>

Here's the SQL def:

CREATE TABLE `hitcounter` (
`id` int(11) NOT NULL auto_increment,
`count` int(11) default NULL,
`lastip` varchar(255) default NULL,
PRIMARY KEY (`id`),
KEY `lastip` (`lastip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;