sloppycode.net
Visitor counter
Text-file based visitor file counter.
Home
›
Code snippets
›
PHP
›
Visitor counter
This is an example of a very basic text file-based graphical visitor counter. You need to have 10 GIF images named "0.gif","1.gif" etc. and a counter text file (in the same directory). This counter file must have read/write permissions (chmod to 755 on Unix platforms).
Like all PHP on sloppycode.net this example was made in PHP 3.x or 4, so unfortunately isn't guaranteed to be error free anymore.
<? // PHP counter // Set these variables $counterFile = "counter.txt"; // name of counter text file $imagesDir = "/images"; // directory where images are kept (no trailing slash) // Open counter text file. $hFile = fopen($CFile, "r+") or die("Unable to open counter file:".$counterFile." for writing"); $counter = $fread ($hFile, filesize ($counterFile)) or die("Unable to read counter file:".$counterFile); $counter = $counter + 1; rewind ($hFile) or die("Unable to rewind counter file:".$counterFile); fwrite($hFile,$newValue) or die("Unable to write counter file:".$counterFile); fclose($hFile) or die("Unable to close counter file:".$counterFile); // Work out length of $counter and seperate into numbers // and bring up GIF files accordingly (0-9.gif) $iDigits = strlen($counter); $gifImages = array(); for ($i = 0;$i < $iDigits;$i++){ $gifImages[$i] = substr($counter,$i,1); } for ($i = 0;$i < $iDigits;$i++){ $showCounter .= "<img src=\"".$imagesDir."/".$gifImages[$i].".gif\">"; } ?> You can now put your counter anywhere in your page by using <?=$showCounter?>
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search
› Sitemap
Buy on Amazon
Buy on Amazon
Buy on Amazon
Buy on Amazon