我发现很难得到EverCookie设置的Cookie值。
我想做的只是简单地检查是否设置了名为的evercookie。如果没有设置,那么我想将其设置为某个数字。
如下所示:
var cookie_value=获取cookie_值;
if(cookie_value==未定义)
将Coookie设置为“12345”
其他的
希望在php代码中使用它。
下面给出了每个用户的使用代码http://samy.pl/evercookie/

var ec = new evercookie();

// set a cookie "id" to "12345"
// usage: ec.set(key, value)
ec.set("id", "12345");

// 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] + " votes<br>");
}
ec.get("id", getCookie);

// we look for "candidates" based off the number of "cookies" that
// come back matching since it's possible for mismatching cookies.
// the best candidate is very-very-likely the correct one

最佳答案

在这个例子中,cookie名是'id',下面是在php中检查它的方法:

<?php
if (isset($_COOKIES['id'])) {
  //... cookie was set
} else {
  //... no cookie was set
  setcookie('id',$somenumber) ;
}
?>

不幸的是,这将只设置主http cookie,而不是所有evercookie元素。但是,在下次刷新时,evercookie代码应该检测到它的一个元素包含一个值,并将所有其他元素设置为相同的值。

10-05 19:25