我发现很难获得evercookie设置的cookie值。
我想要做的只是检查是否设置了名称的evercookie。如果没有设置,那么我想将它设置为某个数字。
如下所示: var cookie_value = get_cookie_value; if(cookie_value == notdefined) 将coookie设为“12345” 其他 想在php代码中使用它。
Eveercoohie使用代码在下面的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
答案 0 :(得分:1)
在示例中,cookie名称为“id”,因此以下是您在PHP中检查它的方式:
<?php
if (isset($_COOKIES['id'])) {
//... cookie was set
} else {
//... no cookie was set
setcookie('id',$somenumber) ;
}
?>
不幸的是,这只会设置主HTTP cookie,而不是所有其他的evercookie元素。但是,在下次刷新时,evercookie代码应该检测到其中一个元素包含一个值,并将所有其他元素设置为相同的值。