Hi Mark,
You need somewhere to store the count, either a database or a text file. Seeing as it's pretty stupid to use a database for just one piece of information, a text file is much better!
First create an empty file called hitcounter.txt.
Then make another file called hitcounter.
php and put in the following code:
- Code: Select all
<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>
That will add 1 each time the file is hit.
You can use:
include ("hitcounter.
php");
to include the file in any other, so that when they hit that page it is counted too.
To make the counter silent (so it doesn't display a number) remove the line "echo $hits[0];"