PHP Text Counter unique reporting fails (still increments)
Posted: Fri Dec 19, 2014 9:02 pm
Script URL: counter.php
Version of script: 1.6
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: PHP Text Counter
Write your message below:
The .php I downloaded this week (1.6) has an error when counting unique users;
it would still increment regardless. I was forced to change it:
// If counting unique hits is enabled make sure it's a unique hit
if ( $count_unique == 1 )
{
if ( ! isset($_COOKIE[$cname]))
{
// Update count by 1 and write the new value to the log file
if ( ! isset($_GET['skip']) )
{
$count = $count + 1;
rewind($fp);
fwrite($fp, $count);
}
else
{
$count = $count + 0;
rewind($fp);
fwrite($fp, $count);
}
// Print the Cookie and P3P compact privacy policy
header('P3P: CP="NOI NID"');
setcookie($cname, 1, time()+60*60*$unique_hours);
}
else
{
// dummy
}
}
else
{
if ( ! isset($_GET['skip']) )
{
$count = $count + 1;
rewind($fp);
fwrite($fp, $count);
}
else
{
$count = $count + 0;
rewind($fp);
fwrite($fp, $count);
}
}
I'm sure you can write a more efficient way of doing it, as this is my
first .php, but this now works for me correctly; hitting refresh on my
browser does NOT increment it, but clearing the cookies and re-doing it
DOES increment it once, as I believe it should. I'm very familiar with
IF structured-programming constructs w/multiple arguments causing
duplicate code in BAL and MASM (macros help).
While I was at it, I need to only view the counter for tracking.
I added the 'skip' parameter; if it exists, do NOT increment the counter.
Otherwise, this is a very nice piece of code. Just gotta remember CHMOD!
My ISP had removed counter support and I was forced into replacing it;
I chose your product. Thankx.
Version of script: 1.6
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: PHP Text Counter
Write your message below:
The .php I downloaded this week (1.6) has an error when counting unique users;
it would still increment regardless. I was forced to change it:
// If counting unique hits is enabled make sure it's a unique hit
if ( $count_unique == 1 )
{
if ( ! isset($_COOKIE[$cname]))
{
// Update count by 1 and write the new value to the log file
if ( ! isset($_GET['skip']) )
{
$count = $count + 1;
rewind($fp);
fwrite($fp, $count);
}
else
{
$count = $count + 0;
rewind($fp);
fwrite($fp, $count);
}
// Print the Cookie and P3P compact privacy policy
header('P3P: CP="NOI NID"');
setcookie($cname, 1, time()+60*60*$unique_hours);
}
else
{
// dummy
}
}
else
{
if ( ! isset($_GET['skip']) )
{
$count = $count + 1;
rewind($fp);
fwrite($fp, $count);
}
else
{
$count = $count + 0;
rewind($fp);
fwrite($fp, $count);
}
}
I'm sure you can write a more efficient way of doing it, as this is my
first .php, but this now works for me correctly; hitting refresh on my
browser does NOT increment it, but clearing the cookies and re-doing it
DOES increment it once, as I believe it should. I'm very familiar with
IF structured-programming constructs w/multiple arguments causing
duplicate code in BAL and MASM (macros help).
While I was at it, I need to only view the counter for tracking.
I added the 'skip' parameter; if it exists, do NOT increment the counter.
Otherwise, this is a very nice piece of code. Just gotta remember CHMOD!
My ISP had removed counter support and I was forced into replacing it;
I chose your product. Thankx.