NinerNet Communications™
Documentation

Contents of /counter.txt

SIMPLE TEXT COUNTER
~~~~~~~~~~~~~~~~~~~


To add a simple, text-based counter to a page, do the following:

1) Create a file named "counter.txt" in the same directory as the pages you want counted.

2) Open the file in a text editor (such as Notepad) and enter the number 0 -- nothing else.
Save the file. (If you are moving an existing site and want to start with a higher number,
simply enter that number instead of 0.)

3) In any page you wish counted and where you want the counter displayed, enter the following
code:

	<?php

	$fp = fopen("counter.txt","r");
	$count = @fread ($fp, filesize ("counter.txt"));
	fclose($fp);
	$count++;
	$fp = fopen("counter.txt","w");
	fputs($fp, $count);
	fclose($fp);
	echo "Hits: $count";

	?>

4) Save the file with a ".php" file extension.

5) Upload the files to your Web server.

6) Use your FTP program to change the permissions on the "counter.txt" file to 666 -- i.e.,
read and write permission for the user, group and world.


That's it! Each time you load the page the counter will (obviously) increment.

If you'd like to change the appearance of the counter in some way, you can add the
appropriate HTML tags to the final "echo" statement -- for example:

	echo "<b>Hits:</b> <i>$count</i>";

This will bold the word "Hits:" and italicise the number. You can also change the context --
for example:

	echo "This page has received $count hits since 1969.";



Home