Tuesday, September 13, 2011

Fransiskus Sutris

Simple Counter PHP

You need a file will be used to record your web visitors. Every times when your web page have been visited, counter script will increase the data file. by using the simple way you can make a simple counter. Firstly you need to create one file named data.txt (put any number in data.txt) and save in same path of your counter.php file.

  <?
  //counter.php
  //check and read file data.txt
  if(file_exists("data.txt"))
  {
    $PF=fopen("data.txt",'r');
    $num=fgets($PF,4096);
    fclose($SP);
    
    //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
    echo "You are $num"."th"." visitor";
  }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 :