A simple hit counter using a text file. The script records every page hit into the text file called log.txt. The total number of hits is then displayed when the counter script is called.
You must create a blank file called log.txt with an initial value of 0.
<?php
$fp = fopen("log.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count++;
echo "Total Hits: $count";
$fp = fopen("log.txt", "w");
fwrite($fp, $count);
fclose($fp);
?>
Assuming you call the script counter.php, then you can call the script by using:
<?php include_once('counter.php'); ?>
Showing posts with label PHP Counter. Show all posts
Showing posts with label PHP Counter. Show all posts
14 December 2009
Subscribe to:
Posts (Atom)