#native_company# #native_desc#
#native_cta#

Simple Hit Logger

By John Holmes
on February 15, 2001

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
// [email protected]

  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>rn");
echo("<center>rn");

// 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>rn");

echo("</center>rn");
echo("</html>rn")

?>