gpt4 book ai didi

php - Evercookie 使用问题

转载 作者:可可西里 更新时间:2023-10-31 23:43:39 27 4
gpt4 key购买 nike

我发现很难获得 evercookie 设置的 cookie 的值。

我想做的只是检查是否设置了名称为 evercookie 的设置。如果未设置,则我想将其设置为某个数字。

类似下面的内容:var cookie_value = get_cookie_value;如果(cookie_value == 未定义)将 cookie 设置为“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

最佳答案

在示例中,cookie 名称是“id”,因此您可以在 PHP 中检查它:

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

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

关于php - Evercookie 使用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6606334/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com