This is quick & dirty:
<?
$page_request = explode("/", $REQUEST_URI);
// that makes an array.
$count_array = count($page_request) - 1;
// so your page name is $page_request[$count_array]
// your counter PAGENAME-counter.txt
// ex: for index.html, it's index.html-counter.txt
// it must exist beforehand, and chmod to 777
$url = $page_request[$count_array] . "-counter.txt";
// open that counter file
$fp = fopen("$url","r")
or die("there's no counter");
// read the data
$data = fread($fp, 4096);
$new_count = $data + 1;
// write the new count to the counter file from the beginning:
fclose($fp);
$fp = fopen("$url","w")
or die("can't open for writing");
fwrite($fp,$new_count);
fclose($fp);
// display the new count:
echo $new_count . " visitors";
?> |