Version: 1.0 Beta

Type: Function

Category: HTTP

License: GNU General Public License

Description: This script simply reads/increments a hit counter from a text file.



<?
// Hit counter 1.0 Beta, programmed by SKREEM
// skreem@skr33m.fsnet.co.uk

  function CountHits() {
    if (!file_exists("hit.log")) {
      $hitlog = fopen("hit.log", "a+");
      fwrite($hitlog, "0");
      fclose($hitlog);
    }

    $hitlog = fopen("hit.log","a+");
    $contents = fread($hitlog, 4096);
    fclose($hitlog);

    $cnt = bcadd($contents,1);

    unlink("hit.log");

    $hitlog = fopen("hit.log","a+");
    fwrite($hitlog, $cnt);
    fclose($hitlog);
  
    return $cnt;
  }

// Execute the CountHits() function and store the result in a variable
$hits = CountHits();

echo("<html>\r\n");
echo("<center>\r\n");

// We then can reference the variable $hits wherever we want...
echo("<font face=Tahoma size=2>This page has been hit <strong>$hits</strong> time(s).</font>\r\n");

echo("</center>\r\n");
echo("</html>\r\n")

?>