Hit counter does not work

Hello everyone,
I try to use a hit counter which used to work years ago. However my transfer to a new file fails.

My trial:
I renamed the functioning html code (whose hits shall be counted) to “filetocount.php”. It is situated in “httpdocs”.

In “filetocount.php” I inserted the following code directly before </body>.

.

<?php
include  "../PHP/funktionen.php"; 
	 $hit=$_GET['hit'];
	 $druck=0;
	 zaehlerplus("ScilabSite_Hits.txt",$_SERVER['REMOTE_ADDR'],$druck,$hit);
?>

The file “funktionen.php” is located in “httpdocs/PHP”

Its code is

<?php
function zaehlerplus($fn,$ip,$druck,$hit)
{
/* Zugriffs-Zähler mit Zeit und IP-Adresse/counter with time and IP*/   
   $tstp=time('void');
   $Datum=date('d.m.o',$tstp);
   $Uhrzeit=date('H:i',$tstp);
   $ServAdd = gethostbyaddr($ip);

   if (file_exists($fn))
   {
     /* read all lines to get to last one */
     $fp = fopen($fn,"r");
	 $i=0;
	 $z[0]="";
      do
      {
	  $i=$i+1;
         $zeile = fgets($fp, 100);
		 $z[$i]=$zeile;
      }  
	  while (!feof($fp));
	  
	  $zeile=$z[$i-1]; /*Letzte Zeile*/
	  $worte = explode(" ",$zeile);  
	  $zahl=$worte[0];  /*Alter Zählerstand/old counter value*/ 
	  fclose($fp);
   }
   else
   {
      /* erster Zugriff  ohne txt-file/ first hit without existing txt.file*/
      $zahl = 0;
   }

   $zahl = $zahl + 1;   /*Neuer Zählerstand/New counter value*/ 
  
   $zeile=$zahl." visits  IP: ".$ServAdd."  Zeit: ".$Datum." um ".$Uhrzeit; 
   if($hit=='selbst'){$zeile=$zeile.' Selbstaufruf';}  /* my hit */
      
   if ($druck){print($zeile);}

   /* Neue Zeile schreiben/write new line */
      $nl = chr(13) . chr(10);   /*Hilfsvariable/auxiliary für line feed und carriage return*/
   $fp = fopen($fn,"a");
   flock($fp,2);
   fputs($fp,"$zeile$nl");
   flock($fp,3);
   fclose($fp);
}
?>

Can anyone give me a clue what should be changed?

Regards
phpdummy1

Sponsor our Newsletter | Privacy Policy | Terms of Service