Count unique visitors only - BUG

In case you have problems with some other PHPJunkyard script (not that there are THAT many).
Post Reply
tomgibson
Posts: 4
Joined: Mon Aug 10, 2009 1:31 am

Count unique visitors only - BUG

Post by tomgibson »

Script URL: www.oxcartdays.com/counter/graphcount.php
Version of script: 1.1
Hosting company: IXwebhosting

Write your message below:

I have the PHP graphical hit counter (PHPGcount) installed and a hit counter on multiple pages each with its own .txt log file. I have the unique visitors setting at "1" but when I navigate my site using the navigation menu, the counter advances every time I re-visit a page once I leave it. For example, if I jump back & forth between two pages, the counter on each page will keep advancing each time I land on the page..it doesn't advance if I refresh the page I am on however. It should only count me the first time i hit the page as a unique visitor. I have the unique hours set at 24 hours. Is this a bug in the script or do I have something set-up wrong?
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Try opening your graphcount.php file in Notepad and change everything from "/* Get current count */" to "/* Is zero-padding enabled? */" into this:

Code: Select all

    /* Get current count */
    $count = trim(file_get_contents($logfile)) or $count = 0;
    $cname = 'gcount_unique_'.$page;

    if ($count_unique==0 || !isset($_COOKIE[$cname])) {
        /* Increase the count by 1 */
        $count = $count + 1;
        $fp = @fopen($logfile,'w+') or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!');
        flock($fp, LOCK_EX);
        fputs($fp, $count);
        flock($fp, LOCK_UN);
        fclose($fp);

        /* Print the Cookie and P3P compact privacy policy */
        header('P3P: CP="NOI NID"');
        setcookie($cname, 1, time()+60*60*$unique_hours);
    }

    /* Is zero-padding enabled? */
Upload the modified file to the browser, close all browser windows then try again.

Does it help?
Last edited by Klemen on Mon Aug 10, 2009 6:51 pm, edited 1 time in total.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
tomgibson
Posts: 4
Joined: Mon Aug 10, 2009 1:31 am

Post by tomgibson »

This stopped the counter from advancing when I swithch back & forth between pages BUT it set the counter at 1. I went in and changed the log file to different number for those pages and opened browser to try it again and it keeps resetting the count to 1. I opened the log file to check and it was 1. Don't know why my other number was replaced by the "1".

So I then set unique to 0 to try and let the counter advance on a refresh but the number stayed at 1.

Anything else you can think of to make it work?
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Sorry, my bad, when I was copying the code I missed two lines. I updated the code in my previous post, please try that one again (just add the top two line that are missing in your script now).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
tomgibson
Posts: 4
Joined: Mon Aug 10, 2009 1:31 am

Post by tomgibson »

It works like a charm when I am on the site, but when I close my browser and re-open my browser & go back to the site, the counter advances one count on all the pages I visit, but only the first time I visit a page during my session. Is that correct? I am unique to my site each time I open my browser and visit it?
DC
Posts: 138
Joined: Sun Dec 09, 2007 9:28 am

Post by DC »

That makes sense to me as I see its setting a cookie so unless Klem says otherwise I would say its working as it should now.

Some have there browsers set to delete all cookies on close as well.
So going back would then count as 1 new count.

DC
To Code Or Not To Code That Is The Question?

Was my post of any help to you? if so please do [url=http://www.clickcraft.net/slice_donations.php][b]Buy Me A Slice[/b][/url] ...
tomgibson
Posts: 4
Joined: Mon Aug 10, 2009 1:31 am

Post by tomgibson »

Makes sense to me DC.. Thank you Klemen very much!!! You are indeed an asset to us all.
Post Reply