1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Page Counter Tool

Discussion in 'Products & Tools' started by Laura Patterson, Aug 2, 2014.

  1. #1
    I do have a quick question about the page counter tool.. I am implementing on the new site I am developing and noticed that when I test a new page it does not seem to add my new view to that page's counter. IS that because it is recording my IP and using it globally? I was hoping the counter could be used for each page of the site but only add unique views for each page.
     
    Laura Patterson, Aug 2, 2014 IP
  2. Laura Patterson

    Laura Patterson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    One more thing to add.. in fact it is not working at all no matter if I wish it to count unique hits or not.
    I ran a test on a different domain and it will not increment a page view. Is this tool not operational?
    If not, I really need someone to suggest somewhere where I can get one that does. I have been searching for a PHP solution but all just count page views but not unique or they just work for a single page only where as I need for multiple pages.
     
    Laura Patterson, Aug 2, 2014 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    A page counter tool is really easy to code up, but since they went of vogue many years ago you may not find reliable scripts anywhere - most will use outdated database code that leaves you vulnerable.

    Basically you just need a table in your database called hits. It will have the following columns
    • id
    • page requested
    • ip
    • useragent
    • datetime
    everytime someone accesses the site it gets a count() of all the hits the page has had

    everytime someone accesses the site it checks to see if the IP and UserAgent have already been logged for the page. If they haven't then it sends an insert to the database with the IP and UserAgent

    Catching both is a good idea because people will typically use a single browser for all their work but they'll have subtly different info in their UserAgent from the guy in the next cubicle for various reasons even though they both share an IP. Bear in mind, too, that visitors from NZ, Singapore, India etc will have a huge number of people sharing IP addresses so my hit might not be counted if some stranger on the other side of the city has also viewed the page - UserAgent helps limit that.
     
    sarahk, Aug 2, 2014 IP
  4. Laura Patterson

    Laura Patterson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Thanks, I actually have a script that I found that works and uses a flat file, except I am getting an error:

    Warning: Cannot modify header information - headers already sent by (output started at /public_html/music/star1/janey-kirk-video.php:55) on line 138

    And line 138 is this call:
    // Set a cookie to prevent user from counting again during this session
    global $COUNTER_USE_COOKIES;
    if($COUNTER_USE_COOKIES === TRUE) {
    $cookie_name = 'HIT_COUNTER_' . $counter_id;
    setcookie($cookie_name, 'TRUE', time() + 3600 * 24 * 356 * 10);

    I have been trying to figure out what the problem is?
    If I turn the cookie option off, the error goes away but you can refresh the page and the counter still adds.
    The reason why i am using this counter is to count video plays and I need it to count one per session.
     
    Laura Patterson, Aug 2, 2014 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    Cookies have to be set before you output a single character to the browser. Move the code higher on the page and just do the echo of the counter down where it's needed.
     
    sarahk, Aug 2, 2014 IP
  6. Laura Patterson

    Laura Patterson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    I am place the following in the head of the document:
    <?php
    require_once('counter/counter.php');
    do_counter_hit('kirk');
    ?>

    counter.php contains the call to set the cookie.
     
    Laura Patterson, Aug 2, 2014 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #7
    you need to wade through your code and look for the errant space if there's no obvious output. Could be as simple as a space before a <?
     
    sarahk, Aug 2, 2014 IP
  8. Laura Patterson

    Laura Patterson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    This is all I have in the header section and I am including the file in the first line.
    <head>
    <title></title>
    <?php require_once('counter/counter.php'); ?>
    <script type="text/javascript">var switchTo5x=true;</script>
    <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
    <script type="text/javascript">stLight.options({publisher: "9dc5c494-7496-41d8-9b72-0a1757c52fb4", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>
    </head>
    <body>
     
    Laura Patterson, Aug 2, 2014 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #9
    <head>
    <title></title>
    <?php require_once('counter/counter.php'); ?>
    Code (markup):
    should really be
    <?php require_once('counter/counter.php'); ?>
    <html>
    <head>
    <title></title>
    Code (markup):
    You can't have anything sent to the browser before you run the counter - and the text for head and title might not be visible to the human eye but it's text that IS sent to the browser.
     
    sarahk, Aug 3, 2014 IP
  10. Laura Patterson

    Laura Patterson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #10
    You are right! I moved both PHP calls to the very top line even before the document decoration and it worked!
    I am kinda new to PHP so that one slipped by my radar.. thanks so much for the insight!
     
    Laura Patterson, Aug 3, 2014 IP