Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
Page counter v0 2Code Wizard, 12-30-2006 |
Page counter
This is the function that opens the file that contains the number of visits.
Things you have to do:
1. Create a txt-file named counter.txt and put the number 0 in it (or whatever number you want your counter to start on).
2. Upload counter.txt to your account. And chmod 666 it (i think its 666).
<?php
function pageCounter($inc) {
$data = "counter.txt";
$file = fopen($data,"r+");
$count = fread($file, filesize($data));
fclose($file);
if ($inc) {
$file = fopen($data,"w+");
$count += 1;
fputs($file, $count);
fclose($file);
print $count;
} else {
print $count;
}
}
?>
Now, you have two options:
1) <? pageCounter(0); ?>
2) <? pageCounter(1); ?>
Option number 1 will NOT make the counter increase, it will only output the number of visits.
Option number 2 will increase the counter and output the number of visits.
This is nice if you have several pages, and want the counter to appear on each page, but dont want the counter to increase for every link being clicked.
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments

