Location: PHPKode > scripts > txtPHPCounter > txtphpcounter/txtPHPCounter.php
<?
/*

TO USE THIS SCRIPT YOU MUST LEAVE THIS INFORMATION 

Title: txtPHPCounter
Author: Dan Beland
WebSite: www.danbeland.com
Email: hide@address.com
©2003 Dan Beland

*/

// Edit These First TWO lines ONLY!
$file_path=$DOCUMENT_ROOT . "/path_to/counter/"; // Path to counter directory
$img_path = "counter/img/";

// DO NOT CHANGE BELOW THIS LINE ------------------------------>
include($file_path . "functions.inc.php");
$RemoteIP = $HTTP_X_FORWARDED_FOR;
if(trim($RemoteIP)=="") {
  $RemoteIP = $REMOTE_ADDR;
}

// Open and read into Array
$file = file($file_path . "hit.log"); 
foreach($file as $line) {
  $arr[count($arr)+1]=explode("|", trim($line));
}
// Add Hit to Array
for($i=0;$i<count($arr)+1;$i++) {
  if($arr[$i][0]==$RemoteIP) {
    $arr[$i][1]++;
    $fnd=TRUE;
    break;
  }
}
if($fnd!=TRUE) {
  $arr[count($arr)+1][0] = $RemoteIP;
  $arr[count($arr)][1] = 1;
}

// Write array back to File
$fp = fopen($file_path . "hit.log", "w");
for($i=0;$i<count($arr)+1;$i++) {
  for($a=0;$a<count($arr[$i]);$a++) {
    $write = fputs($fp, trim($arr[$i][$a]));
    if($a!=count($arr[$i])-1) { $write = fputs($fp, '|'); }
  }
  if(($i>0)&&($i!=count($arr))) { $write = fputs($fp, "\n"); }
}
fclose($fp);
?>
Return current item: txtPHPCounter