Posted on April 18th, 2007 at 9:46 pm by Andrew
I think everyone starts PHP this way and I remember the satisfaction it gave me when I first used this (back on AlienActivity.com), it's just a nice nifty little tool to get you started on PHP and it's something many sites wouldn't be without!
To keep it simple I've chosen just to use text files rather than databases, you'll need to CHMOD the file you store your counts in to 777. Here goes, once again it's a fairly self-explanatory script that I'll just annotate in-line.
PHP:
-
<?
-
$file = "counts.inc"; // Where we store the counting
-
$counts=$counts+1; // Add 1 to the current counter value
-
-
/* It's worth noting that it is in fact necessery to close the file and re-open it in order to write the incremented count, I originally wrote this script without doing so and discovered an error where it counted up in unuaul integers of 1, 2, 13, 1214, 12131215, for more info please read here: http://www.moon-hosting.co.uk/php/tutorials/PHP_Lecture4 _Files.doc */
-
?>
How easy was that?!