html counter
•
29 Apr 2010, 02:34
•
Journals
hey,
i am in need of a simple html counter for a private webpage. without any advertises and stuff
thanks for your help ;) (i got no mysql on the webserver!)
i am in need of a simple html counter for a private webpage. without any advertises and stuff
thanks for your help ;) (i got no mysql on the webserver!)
<?php
/**
* @author Viperius
* @copyright 2010
*/
$counter_file = "counter.txt";
if( !($ref = fopen($counter_file, "r") ) )
die ("An error occured, cannot open file");
$counter = (int) fgets($ref);
fclose($ref);
$counter++; // updating counter
echo "You are visitor $counter";
// writing updated counter to counter.txt
$ref = fopen($counter_file, "w");
fwrite($ref, $counter);
// close not needed, but a good habit
fclose($ref);
?>
Remember to have "counter.txt" in the same dir. Also, webspace need php support.