Sublime directory Surf the web anonymous Pagerank Monitor


A simple counter in PhP

Nikolas
Fri 26 August 2005, 03:09 pm GMT +0300
Here is the code for a very simple counter that you can add to your site :

Code:
<?php
if(file_exists("hits.txt"))
{
    
$hits file_get_contents("hits.txt");
}else{
    
$hits=0;
}
$hits++;

$ha fopen("hits.txt""w");
fwrite($ha$hits);
fclose($ha);
?>

You can add it to the .php page that you want to count, plus you can add this code if you want it to be visible :

Code:
<?php
echo $hits." visitors";
?>


NumBa1Stunna516
Thu 1 September 2005, 09:37 pm GMT +0300
I actually prefer the hitcounters that use a database. I feel you can do much more with a database and text files. Its almost a bias. But its good code though for someone who doesnt have a database to work with.

Nikolas
Fri 2 September 2005, 11:49 am GMT +0300
The best is having a log analyzer, but all these funzy stuff are not usefull for small sites. I mean you don't need a sofisticated statistics program when you have 30 visits per day...

Bobster
Mon 5 September 2005, 08:10 am GMT +0300
Interesting, I'm going to try it out. Perfect for me.

NumBa1Stunna516
Thu 8 September 2005, 07:32 am GMT +0300
Yea I guess you are right, small sites dont need an advanced stats tracker.

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional