A few years ago I added an Extension to the WYSIWYG Web Browser program I use, in order to count the visitors to my website donjohnson24.co.uk, but cannot recall from where it came. The extension uses cookies and is intended to check that the person connecting to the site is not ME, and that returns to the page with the counter do NOT add to the count. I recently noticed an error message - produced by $user being undefined before use - and corrected that satisfactorily. Having looked at the script, my query is that although the Extension appears to function OK - not counting MY visits and returns to the counter-containing page - I can't see why? The code involving DONCHECK doesn't seem to do what is intended, but somehow seems to work. I must admit to very little experience with PHP, and though I have used many program languages in the past, I am now 84 years old, and my memory and programming skills have been stagnating for some years.
It may be that I just misunderstand how cookies work, but if anyone can explain, or point out where the script should be corrected, I would be most grateful.
The Extension stores itself before the html tag, and is shown below. The window for entering parameters for the Extension is also attached.
<?php
$revisit = "No";
//check if first visit
if(isset($_COOKIE["first"]))
{
$revisit = "Yes" ;
$play = "$secplay$" ;
}
else
{
$cookie_name = "first";
$cookie_value = "XX";
setcookie($cookie_name, $cookie_value);
$play = "$firstplay$" ;
}
//check if MY computer
$cookie_name = "$identcookie$";
$user = " ";
if(isset($_COOKIE[$cookie_name]))
{
$user = $_COOKIE[$cookie_name];
}
else
{
$cookie_name = "$identcookie$";
$cookie_value = "$identname$";
setcookie($cookie_name, $cookie_value);
}
// get the visit count, and update if first visit and NOT on my computer
$file = fopen("$file$", 'r');
$data = fread($file, filesize("$file$"));
fclose($file);
if ($data !== false)
{
$hits = intval($data);
if ($user != "$identname$" && $revisit != "Yes")
{
$hits++;
$file = fopen("$file$", 'w');
flock($file, LOCK_EX);
fwrite($file, $hits);
flock($file, LOCK_UN);
fclose($file);
}
}
?>