Creating a visible page counter
is something I'd like to explore next. I have a stats program which tells me how
many visitors I have already for each page that is essentially invisible, but I
have received a number of emails expressing interest in how to make a counter
using PHP that is visible. The code below inserted into a page counts the
visitors and display the results dynamically.
<?
if(file_exists("count.dat"))
{
$exist_file = fopen("count.dat",
"r");
$new_count = fgets($exist_file,
255);
$new_count++;
fclose($exist_file);
// to be invisible counter comment out next line;
print("$new_count people have visited this page");
$exist_count = fopen("count.dat", "w");
fputs($exist_count, $new_count);
fclose($exist_count);
}
else
{
$new_file = fopen("count.dat", "w");
fputs($new_file, "1");
fclose($new_file);
}
?>
23645
people have visited this page
To insert
the code to a page where you want the counter displayed you would use the
following code:
<? require("/path/to/count.dat");
?>
It looks great script thanks for sharing.I think using PHP script has many benefits over Java Script.I think PHP page counters give you ample information on what order the visitors are accessing pages and what they prefer.PHP page counters are open source and they are not at all depended on the browser configuration and as a result they are capable of presenting you the best results.
ReplyDeletehttp://counterforsite.com/php-page-counters/