Cookies

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
donjohnson24
 
 
Posts: 118
Joined: Thu Sep 27, 2012 9:32 pm
Location: Bridgwater, Somerset, UK
Contact:

Cookies

Post by donjohnson24 »

Some years ago I wanted to add visitor counters to my website Home page. I also wanted to avoid counting my own visits, and returns to the Home page from other pages. I ended up with the Extension, PHP Counter7 - shown below. I recently noticed an error message appearing when starting my website, which I eventually corrected by editing PHP Counter7 using Extension Builder for WYSIWYG Web Builder, and it now works fine.

The Extension produces the inserted HTML code at Start of Page shown below.

I am obviously using a Cookie named DONCHECK, but I have no idea where to find it to see what it contains.
I also cannot remember where I obtained the basis of PHP Counter7, and cannot find any Help file.

I Googled 'Cookies' 'till I was blue in the face but could not really find anything that tells me WHERE to find DONCHECK, so any suggestions would be very appreciated.

------------------

<?php

$revisit = "No";

//check if first visit
if(isset($_COOKIE["first"]))
{
$revisit = "Yes" ;
$play = " " ;
}
else
{
$cookie_name = "first";
$cookie_value = "XX";
setcookie($cookie_name, $cookie_value);
$play = "autoplay" ;
}

//check if MY computer
$cookie_name = "DONCHECK";
$user = " ";
if(isset($_COOKIE[$cookie_name]))
{
$user = $_COOKIE[$cookie_name];
}


// get the visit count, and update if first visit and NOT on my computer
$file = fopen("Counter.txt", 'r');
$data = fread($file, filesize("Counter.txt"));
fclose($file);
if ($data !== false)
{
$hits = intval($data);

if ($user != "Don3" && $revisit != "Yes")
{
$hits++;
$file = fopen("Counter.txt", 'w');
flock($file, LOCK_EX);
fwrite($file, $hits);
flock($file, LOCK_UN);
fclose($file);
}

}
?>

----------------

Image
User avatar
donjohnson24
 
 
Posts: 118
Joined: Thu Sep 27, 2012 9:32 pm
Location: Bridgwater, Somerset, UK
Contact:

Re: Cookies

Post by donjohnson24 »

Well, with no help forthcoming, I decided to try once more, and eventually found out how to view cookies in Chrome, and I saw that my DONCHECK cookie was NOT being created. I looked again at the Extension PHP Counter7, and it finally dawned on my 84-year-old brain that this was where all the cookie stuff was happening. It took me a while to go back to old programming principles to sort out how to get the script correct, but I did eventually get it to work. Just in case anyone who has nothing better to do ends up reading this and is curious, below is the file I ended up with. I even read the Help for Extension Builder, and I now understand the basic way the extension is created.

<?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);
}

}
?>
Post Reply