After reading Jethro's post on Website Administration, I felt compelled (ok, maybe not compelled, but inspired) to write something marginally useful in PHP. The simplest thing I could think of that would be useful was a hit counter, so here it is.
This one uses a file-based count system, but I'll write a database version of it some time in the near future. It has not been tested due to the fact that I don't have a working apache setup on this computer at the moment, but I see no reason why it shouldn't work.
PHP Code:
<?
/*
PHP Simple Hit Counter
Text File Version
Andrew J. Bennieston
*/
// Read Current Counter
// If counter.txt does not exist, set counter to 0
$file = fopen("counter.txt", "r");
if ($file == false)
{
$counter = 0;
}
$counter = fread($file, 8);
$ok = fclose($file);
// Increment counter
$counter++;
// Write new count to counter.txt
$file = fopen("counter.txt", "w");
if ($file == false)
{
echo "Error: Could not create or open counter.txt";
}
$ok = fclose($file);
// Print counter to screen:
?>
<font size="5"><?= $counter ?></font>