Results 1 to 2 of 2

Thread: Hit Counter Code

  1. #1
    Join Date
    Jun 2010
    Location
    Chennai
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hit Counter Code

    Hit Counter

    Code:

    $fp = fopen("visitors.txt", "r");
    $j= fread($fp,filesize("visitors.txt"));
    fclose($fp);
    $j=$j+1;
    $fp1 = fopen("visitors.txt", "w");
    fwrite($fp1,$j);
    fclose($fp1);
    echo $j;

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    file put contents and file get contents is a simpler solution if php 5 is installed.

    PHP Code:
    $file_name "visitors.txt";
    $fp file_get_contents($file_name);
    $fp++;
    file_put_contents($file_name$fp);
    echo 
    "Visitor Number:" $fp
    This will give false counts though because you aren't accounting for bots/spiders, reloads, etc...
    Corrections to my coding/thoughts welcome.

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
  •