Simple, Easy PHP Hit Counter
3
If it's a .php page, you can simply include this file where you want a hit counter to appear.
One file - text output. Very simple, very easy. Based off the filename of the page (creates a pagename.counter file to hold the count).
(No use for it myself - made it for a friend).
One file - text output. Very simple, very easy. Based off the filename of the page (creates a pagename.counter file to hold the count).
(No use for it myself - made it for a friend).
<?
//
// phpcounter.php
//
$myPage = $_SERVER['DOCUMENT_ROOT'];
$lastPeriod = strrpos($myPage,".");
$lastSlash = strrpos($myPage,"/") + 1;
if(!$lastSlash)
{
$lastSlash=1;
}
$myLength = $lastPeriod-$lastSlash;
$newString = substr($myPage,$lastSlash,$myLength);
$newString = $newString . '.counter';
$existingfile = file_exists($newString);
if(!$existingfile)
{
$hits[0] = 0;
$fp = fopen($newString , "w");
fputs($fp , "$hits[0]");
fclose($fp);
}
$hits = file($newString);
$hits[0]++;
$fp = fopen($newString , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>





Visit us at http://www.stutimandal.com