Basic file based hit counter

Basic file based hit counter
Very basic hit counter based on a plain text file, built using PHP.
1. <?php
2. // If the hits file doesn't exist, create it
3. if(!file_exists('Hitcounter.txt'))
4. {
5.        $FHits = fopen ( 'Hitcounter.txt', 'w');
6.        fwrite($FHits, 1);
7.        $Hits = 1;
8. }
9. else
10. {
11.        // Get counter and add 1 to it
12.        $Hits = @file('Hitcounter.txt');
13.        $Hits = $Hits#66CC66 0] + 1;
14.       
15.        // Write back to the file
16.        $FHits = fopen('Hitcounter.txt', 'w');
17.        fwrite($FHits, $Hits);
18.        fclose($FHits);
19. }
20. // Show the number of hits
21. echo $Hits;
22. ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top