how to make a php counter

If you would like to know how many people visited your page, you should have a counter. The most simple counter in PHP looks like this:

(in the body section)

<?php
$fp=fopen("acc.txt","r");
$count=fgets($fp,1024);
fclose($fp);
$fw=fopen("acc.txt","w");
$cnew=$count+1;
$countnew=fputs($fw,$count+1);
echo "<br><br>You are the $cnew reader of this article";
fclose($fw);
?>

It opens the file, reads it content, increases the number and writes it back. Finally prints some text to the page.

To make it work create a file called acc.txt and write a 1 into it.
You also have to rename your .html file to .php !

As I told before it is a very simpe counter. It can be cheated easily by refreshing the page. To avoid this you should check the php session...

I wish you many-many visitors :)

You are the 4528 reader of this article

pohar 2006.01.17.

back

(c) 2000-2006 H A R D R E A D

 
news
members
releases
articles
links