Follow us on...
Follow us on Twitter
Register
+ Reply to Thread
Results 1 to 2 of 2

Thread: PHP Hit Counter

  1. #1
    Senior Member ciullaanthony's Avatar
    Join Date
    Jan 2012
    Location
    Arlington, Texas
    Posts
    103
    Feedback Score
    0

    PHP Hit Counter

    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;
    
    ?>
    Need Help? PM me for help.Thanks for visiting: http://www.webdevforum.com/

  2. #2
    Member Noble Genius's Avatar
    Join Date
    Jan 2012
    Location
    Northeast, U.S.A
    Posts
    42
    Feedback Score
    0
    This is definitely a great start to coding. However, keeping in mind that there are much more advanced php counters, you're better off using those, or improving on this. But this is how everyone starts, and you're certainly doing well. It would be nice if you continue to implement features on to this.
    http://h5network.com/ - Design & Coding Forums

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts