Page 1 of 1
Count unique visitors only - BUG
Posted: Mon Aug 10, 2009 1:55 am
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?
Posted: Mon Aug 10, 2009 9:08 am
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?
Posted: Mon Aug 10, 2009 4:22 pm
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?
Posted: Mon Aug 10, 2009 6:52 pm
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).
Posted: Mon Aug 10, 2009 9:15 pm
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?
Posted: Mon Aug 10, 2009 10:19 pm
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
Posted: Tue Aug 11, 2009 3:12 pm
by tomgibson
Makes sense to me DC.. Thank you Klemen very much!!! You are indeed an asset to us all.