question about txt & php

Discussion in 'PHP' started by izlik, Jun 30, 2007.

  1. #1
    Hello.

    I wonder how i can make my page update a .txt file each time someone visit my page? when someone visits the number in the .txt should change 1 number, like each visit 1 then 2 thne 3, 4, 5, etc, how can i do this? the file is called "view.php" and the txt is called "view.txt"
     
    izlik, Jun 30, 2007 IP
  2. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #2
    $filename = "counter.txt";
         $count = file_get_contents($filename);
         if ($count == null)
            $count = 0;
         echo $count;
         $count++;
         $handle = fopen($filename, "w+");
         fwrite($handle, $count);
         fclose($handle);
    PHP:
     
    GeorgeB., Jun 30, 2007 IP
  3. rickdev

    rickdev Peon

    Messages:
    53
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is there a reason you wanted to use a file an not a DB for this?
     
    rickdev, Jul 1, 2007 IP
  4. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Cheers m8 :) however, i dont want the counter number to be shown on my page :/ i just want it to count into the txtfile for my private stats checking.
     
    izlik, Jul 1, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Remove this line from his script:
    
    echo $count;
    
    PHP:
     
    nico_swd, Jul 1, 2007 IP