View Single Post
  #3 (permalink)  
Old Feb 14th, 2004, 22:09
Webforumz Staff Webforumz Staff is offline
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
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];"