www.webdeveloper.com
Results 1 to 4 of 4

Thread: Is it possible to make webcounters from PHP

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,704

    Is it possible to make webcounters from PHP

    I've used third-party webcounters for many years, but recently, the site has been experiencing difficulties, so I was wondering if it's possible to create my own.


    Yes, I use webcounters. The wisdom thereof is beside the point; it's a personal page, so it's allowed to suck.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    Should be simple. Just need to decide how/where you want to store the count, and whether or not you want to do any filtering, such as trying to not count search engine bots, etc.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,704
    How would you set it up?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    Something real simple (and untested):

    First, create a file (I'll call it counter.txt for this example) with just one line with the value "0" (zero, no quotes).

    Then on any page where you want to increment the count:
    PHP Code:
    <?php
    file_put_contents
    ('counter.txt'trim(file_get_contents('counter.txt')) + 1);
    ?>
    Any place you want to output the current count:
    PHP Code:
    <?php
    echo trim(file_get_contents('counter.txt'));
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles