Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Page counter v0 2

Code 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.
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions