PHPBuilder - Access Counter

RSS Twitter

Access Counter

by: Paul Lewis
August 13, 2004

Version: 1.2

Type: Full Script

Category: HTTP

License: GNU General Public License

Description: This counter can do: -count how many visits you got :-) -ignoring reloads(if the new ip is the same or older than "Wait") as the last one accessed ! -show the date on which the counter started (in a unix timestamp See at the end for formating) -show the last visited date/time(in a unix timestamp See at the end for formating) -show the ip of the last visitor -show pictures (named 1.jpg, 2.jpg ...0.jpg) If ya like this or got better ideas drop me a line:


 This counter creates a file that lists all ip addresses
that have visited the site.  If a new ip address visits
the counter increases bye one and adds the ip address to
its list.  A cookie is put on the computer also to speed
up to process for old users... a long list of ip address
can take a while to search.  The addresses are not in order.
 1-Check for cookie that says been to page
 2-If cookie then do nothing (no code required)
 3-If no cookie then check for ip adress in database
 4-If ip adress found create new cookie
 5-If ip adress not found then create new cookie,
  add 1 to the count and add ip adress to list
 6-display count

//check for ipaddress
function findip($ip, $filename){
 $file = fopen($filename, "r");
 $contents = fread($file, filesize($filename));
 //get data
 $tok = strtok($contents,"\n");
 for ($i = 0; $i < $count; $i++){
  if ($ip == strtok("\n")){
   return 1;
 return 0;

$filename = "count.txt";

//check if file exists
if (!file_exists($filename)){
 $file = fopen($filename , "w");
 fwrite($file, "0");

//find count - number of ip addresses
$file = fopen($filename,"r");
$count = fgets($file); //get number of visiting ips

//look for cookie and ipaddress
//decide if person has visited before
if ($visited == NULL){
 if (!findip($REMOTE_ADDR, $filename)){
  $count = $count + 1;
  $file = fopen($filename, "r+");
  fwrite($file, "$count");
  $file = fopen($filename, "a+");
  fwrite($file, "$REMOTE_ADDR\n");






//display count of visited ip addresses
for ($i=0; $i < strlen($count); $i++)
  $sign = substr($count, $i, 1);
  print("<img src=\"$sign.jpg\" border=\"0\" alt=\"$sign\">");



Comment and Contribute

Your comment has been submitted and is pending approval.

Paul Lewis



(Maximum characters: 1200). You have characters left.