#native_company# #native_desc#
#native_cta#

Unique IP Counter

By joe szymczak
on November 5, 2001

Version: 0.000001

Type: Full Script

Category: HTML

License: GNU General Public License

Description: This is a pretty rudimentary way to keep track of unique hits, but It works.

<?
/* Just put this code into your index page, and put $unique_ip wherever you want the counter number.  Be careful because the ip list file must be world changeable.
  this is just a quick and dirty.  If you feel that you want to flame me for this, don't bother,I know it sux.
  Thanx,

  joe

*/




//-------------------------------------------------------------------begin ip_filter
 function ip_filter($ip_array, $ip_number)
 {
  //This function checks if $ip_number is in an array of IP addresses
  //parameters = an array of ip addresses and an IP address
  //returns the ip address if the address is not already in the array
  //returns 999 if the ip address is in the array
  $ip_add=0;
  for($n=0;$n<count($ip_array);$n++)
    {
      if($ip_add != 999 and $n > 0)
          {
          if(strcmp(trim($ip_array[$n]), $ip_number) == 0)
            {
              $ip_add=999;
            }
          else{$ip_add = $ip_number;}
         }
    }
   global $unique_ip;
   $unique_ip=count($ip_array);
   return($ip_add);
 }
 //-------------------------------------------------------------------end of ip_filter



 //------------------------------------------------------------------begin ip_list_read
 function ip_list_read($read_file)
 {

  if($counter_file = fopen($read_file, "r+"))
  {

    $p=0;
    while(!feof($counter_file))
    {
      $p++;
      $counter_file_field[$p] = fgets($counter_file, 1024);

    }
  }

  fclose($counter_file);
  return($counter_file_field);
  }
  //------------------------------------------------------------------end of ip_list_read


  //-------------------------------------------------------------------begin ip_array_write
  function ip_list_write($file_name, $ip_number)
  {
  //
  //
  //
  //           as of now the file that keeps the ip list must be created, but
  //            it would be easy to change the switch on the fopen() function.
  //
  //
  //

    if($counter_file = fopen($file_name, "a"))
    {
      if($ip_number != 999)
      {
        fwrite($counter_file, $ip_number . "n");
      }
    }

    fclose($counter_file);
  }
  //------------------------------------------------------------------end of ip_list_write


$z=ip_list_read("counter.txt");
$ip_address=$REMOTE_ADDR;
$y=ip_filter($z,$ip_address);
ip_list_write("counter.txt",$y);



//------------------------------------------------------------------------------------------end of counter code---------------------------------------------
?>