dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Is it possible to make webcounters from PHP

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

    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
    21,434
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,434
    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'));
    ?>
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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