The Dreaded Evercookie and CakePHP

So, I'm trying to implement evercookie on the cakePHP website, but I am getting some really, really weird results. I just copied and pasted the code files into my app / webroot directory, and it seems I am not getting any 404 errors, but my cookies are not saved - they are rewritten every time. What's even weirder, when I load a page, it sends at least 90 GET requests to Google.com and stores 4-5 SQLite databases in Google Chrome; there is only one on the evercookie website.

My code on my generated HTML page:

var ec = new evercookie(); // set a cookie "id" to a random 10 character string // usage: ec.set(key, value) ec.set("id", "vm5m172dyg"); // retrieve a cookie called "id" (simply) ec.get("id", function(value) { alert("Cookie value is " + value) }); // or use a more advanced callback function for getting our cookie // the cookie value is the first param // an object containing the different storage methods // and returned cookie values is the second parameter function getCookie(best_candidate, all_candidates) { alert("The retrieved cookie is: " + best_candidate + "\n" + "You can see what each storage mechanism returned " + "by looping through the all_candidates object."); for (var item in all_candidates){ document.write("Storage mechanism " + item + " returned: " + all_candidates[item] + "<br>"); } } ec.get("id", getCookie); // we look for "candidates" based off the number of "cookies" that // come back matching since it possible for mismatching cookies. // the best candidate is most likely the correct one 

Part of this code is written to my document, and here is the output (which looks good to me):

 Storage mechanism userData returned: undefined Storage mechanism cookieData returned: d9g6mfoo4y Storage mechanism localData returned: d9g6mfoo4y Storage mechanism globalData returned: undefined Storage mechanism sessionData returned: d9g6mfoo4y Storage mechanism windowData returned: d9g6mfoo4y Storage mechanism historyData returned: undefined Storage mechanism pngData returned: d9g6mfoo4y Storage mechanism etagData returned: d9g6mfoo4y Storage mechanism cacheData returned: d9g6mfoo4y Storage mechanism dbData returned: d9g6mfoo4y Storage mechanism lsoData returned: d9g6mfoo4y Storage mechanism slData returned: d9g6mfoo4y 

My problem is, how can I prevent 90+ requests sent to Google? I have no idea why this is being done. If I have, say, ten users on the site right away (which is not unbelievable), then more than 900 (0). And any of you have an idea why the cookie is reset every time I refresh the page? What I'm trying to prevent.

+4
source share
1 answer

Well, don't I feel stupid! It turned out that calling ec.set () at the beginning of the code set a cookie at the beginning of each page load. So, I faked something, and now it works. And I no longer send 90 requests to Google.

 // retrieve a cookie called "id" (simply) ec.get("id", function(value) { if(value == undefined){ // set a cookie "id" to a random 10 character string // usage: ec.set(key, value) ec.set("id", "<?php echo $hash ?>"); } else { // do nothing } }); 
+1
source

Source: https://habr.com/ru/post/1345155/


All Articles