Tuesday, September 13, 2011

Fransiskus Sutris

PHP graphical hit counter (picture)

If you want to make your counter looked more beautiful, you can use image file to arrange it. This article will explain how to make beautiful counter with image. You need to prepare any file image that contain number 0.jpg until 9.jpg. Then you make a file named data.txt and put any number in data.txt. Don't forget to put data.txt in same place of counter.php. For image file like 0.jpg until 9.jpg, put them in folder './picture/'.

Next, create php file named counter.php and paste code below..

<?php
  //counter.php
  //check and read file data.txt
  if(file_exists("data.txt"))
  {
      $PF=fopen("data.txt",'r');
    $num=fgets($PF,4096);
    fclose($PF);
  
    //add value to $num
    $num++;
    $PF=fopen("data.txt",'w');
    fputs($PF,$num);
    fclose($PF);
    chop($num);
  
    $nb_digits=max(strlen($num),6);
    $num=substr("0000000000".$num,-$nb_digits);
  
    //show  on page
    $num=preg_split("//",$num);
  
    echo "Number of visitors are
";
    for ($i=0; $i<=$nb_digits;$i++) 
    { 
      if($num[$i]!="") 
      {

            echo "<IMG SRC=\"./picture/$num[$i].jpg\">";
      }
    }
  }else
  {
      echo "file data.txt no found.";
  }
?>


Fransiskus Sutris

About Fransiskus Sutris -

Halo, perkenalkan saya Fransiskus Sutris. Saya berbagi tips and trik di blog saya ini dan semoga apa yang saya bagi disini bisa bermanfaat bagi anda yang membacanya.

Subscribe to this Blog via Email :