CoderZone.org

Category: >> PHP Code >> Flat file counter Bookmark and Share

<< lastnext >>

Snippet Name: Flat file counter

Description: Simple demo of a flat file counter.

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?php
 
$visitor_ip = $HTTP_COOKIE_VARS["user_ip"]; 
$counter = "counter.txt"; 
$counter_file_line = file($counter); 
 
if(!$vistor_ip) 
{ 
  setcookie("user_ip", $REMOTE_ADDR, time()+360000); 
  $counter_file_line[0]++; 
  $cf = fopen($counter, "w+"); 
  fputs($cf, "$counter_file_line[0]"); 
  fclose($cf); 
} 
elseif($vistor_ip != $REMOTE_ADDR) 
{ 
  $counter_file_line[0]++; 
  $cf = fopen($counter, "w+"); 
  fputs($cf, "$counter_file_line[0]"); 
  fclose($cf); 
} 
?>
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 7