Step 1: We need to create a script called ‘counter.php’ and a text file called ‘hits.txt’ WITH a value of 0 [You Just Create A Text File And Put Number ZERO On That And Save It], if you are not doing this your counter script wont work.Make sure the TXT file it has enough permissions.
Review: You should now have 2 files open, ‘counter.php’ open with nothing in it and ‘hits.txt’ open with a ’0′ in it.
Step 2: CLOSE ‘hits.txt’ (We don’t need it any more for now) Now we need to start PHP coding, so first we do is enter the basic page outline as used in most php pages. Then insert this code into the page you want the hits to be counted.
Code:<?php $open = fopen(“hits.txt”, “r+”); $value = fgets($open); $close = fclose($open); $value++; $open = fopen(“hits.txt”, “w+”); fwrite($open, $value); // variable is not restated, bug fixed. $close = fclose($open); echo $value; ?>



LinkBack URL
About LinkBacks





Reply With Quote
However, keeping in mind that there are much more advanced php counters, you're better off using those, or improving on this. 
Bookmarks