PHPBuilder - Hit Counter

RSS Twitter

Hit Counter

by: Drew Bryson
January 11, 2003

Version: 1.0

Type: Full Script

Category: HTTP

License: GNU General Public License

Description: Basic hit counter we made as a little project to learn about PHP. 2 Files


// Simple counter by Sketch and kn64

$filename = "hit.log"; // sets File path as variable

$fp = fopen($filename, 'r'); // opens file with read permissions

$hits = fgets($fp); // reads file to 4096bytes

fclose($fp); // closes file

$hits++; // increments variable

$fp = fopen($filename, 'w'); // opens file for writing

fputs($fp, $hits); // adds $hits

fclose($fp); // closes file once more

echo ("<p>$hits people have entered this site!</p>"); // Displays it on website

Comment and Contribute

Your comment has been submitted and is pending approval.

Drew Bryson



(Maximum characters: 1200). You have characters left.