Flat file hit counter with image display
By: Daniel

If you liked the flat file hit counter tutorial, this is a little more advanced. This uses the same basic concept for counting and writing the hits, but is different in showing hits. Use the following code:

<?php
$file = "hits.dat"; // Hit count file
$fp = @fopen($file, "r"); // Open hits in readonly
$count = @fread($fp, filesize($file)); // get hits

@fclose($fp); // close file
if($count) {
  $count++; // Add 1 to hits if hits exist
} else {
  $count = 1; // If no hits make hits1
}
$fp = fopen($file, "w"); // Open file for writing

@fputs($fp, $count); // Write hits

@fclose($fp); // close file
for($i=0;$i<strlen($count);$i++) {
  $img = substr($count,$i,1); // Get next image
  $hits .= "<img src='images/$img.gif'>";
}
echo $hits;
?>

If you want to just display the hits without counting them use the following code:

<?php
$file = "hits.dat"; // Hit count file
$fp = @fopen($file, "r"); // Open hits in readonly
$count = @fread($fp, filesize($file)); // get hits

@fclose($fp); // close file
for($i=0;$i<strlen($count);$i++) {
  $img = substr($count,$i,1); // Get next image
  $hits .= "<img src='images/$img.gif'>";
}
echo $hits;
?>

Please make sure that your hits.dat file is chmoded to 666, which is all read and write permissions.

You can get as creative as you like with the images used in showing your hits. If you need some basic images you can use the following images:
0.gif1.gif2.gif3.gif4.gif5.gif6.gif7.gif8.gif9.gif

5 Votes | Average: 4.4 out of 55 Votes | Average: 4.4 out of 55 Votes | Average: 4.4 out of 55 Votes | Average: 4.4 out of 55 Votes | Average: 4.4 out of 5 (5 votes, average: 4.4 out of 5)
Loading ... Loading ...
del.icio.us:Flat file hit counter with image display digg:Flat file hit counter with image display spurl:Flat file hit counter with image display wists:Flat file hit counter with image display simpy:Flat file hit counter with image display newsvine:Flat file hit counter with image display blinklist:Flat file hit counter with image display furl:Flat file hit counter with image display reddit:Flat file hit counter with image display fark:Flat file hit counter with image display blogmarks:Flat file hit counter with image display Y!:Flat file hit counter with image display smarking:Flat file hit counter with image display magnolia:Flat file hit counter with image display segnalo:Flat file hit counter with image display

2 Responses to “Flat file hit counter with image display”

  1. I-RoBoT@Corp. Says:

    i use it it woks fine

  2. Xfuryion Says:

    Nice but how can i set one counter on a profile with [img][/img] it aint working

Leave a Reply

eXTReMe Tracker
geovisitors