Your own PHP hitcounter.

Discussion in 'PHP' started by Sphinx1994, Nov 15, 2008.

  1. #1
    Don't use sites like, h.ttp://www.amazingcounters.c.om/, they just require you to leave ads on there, have you're own! It's easy!

    make a file called hitcounter.php,

    Place this inside:

    <?php
    
    $filename = 'hits.txt';
    $handle = fopen($filename, 'r');
    $hits = trim(fgets($handle)) + 1;
    fclose($handle);
    
    $handle = fopen($filename, 'w');
    fwrite($handle, $hits);
    fclose($handle);
    
    //slash next line hide hits, although hits will still be counted.
     echo $hits;
    
    ?>
    Code (markup):
    Now make a txt file called hits.txt, you can edit the amount of hits at any time, you now just need to include the hitcounter.php into your site. Just use this code:

    On the demo below, I used this code:

    <br><font size="1" face="Arial">This game has been played <?php include("hitcounter.php"); ?> times!</font>
    Code (markup):
    But the code is just:

    <?php include("hitcounter.php"); ?>
    Code (markup):
    Enjoy.

    DEMO:
    [w]ww.playelite.[o]rg/games/fmx_team/
     
    Sphinx1994, Nov 15, 2008 IP