A simple application and one you can put in any page. For example you could drop a single include() line in any PHP page you like to show a hit-counter for, or tell your web server to include this script at the bottom of every page (IIS and Apache at least can do this).
This is a text counter, not one with images..
<?
/* Start of the script. If there's a counter file, read it and get the current
* number of hits from it. Then we add one, display the number, and rewrite the
* file. */
if ( is_file("counter.txt") ) {
/* The file exists, so read it. The file() function reads a whole file
* into memory. With a counter file, which is tiny, there's no problem
* with this. The file in memory is stored as an array with one line
* per array item, so array[0] is the first line, etc. We only need the
* first line */
$file = file("counter.txt");
$count = rtrim($file[0]);
/* So $count now contains the first line, minus any whitespace and/or
* newlines at the end. This means $count should be just a number.
* Lucky for us, PHP's clever enough to turn useless text into 0 as a
* number, so we can just add 1 to $count and save that, whatever was
* in there before! */
$count++;
} else {
// There was no counter file, so we'll start from scratch.
$count = 1;
}
/* Now write the count back to a file, and display the number */
/* First, open the file to write .. */
if ($file_pointer = fopen("counter.txt", "w") ) {
/* Write the counter to the file we just opened */
fwrite($file_pointer, $count);
/* Close the file */
fclose($file_pointer);
} else {
/* $file_pointer wasn't set, so fopen() failed,
* so we can't save the counter. Say so! */
echo "Couldn't save counter!";
}
// Finally, show the counter.
echo "This page has been visited $count times";
?>