所以我试图在一个埃弗曲奇网站上实现cakePHP,但是我得到了一些非常非常奇怪的结果。我刚刚把代码文件复制并粘贴到我的app/webroot目录中,我似乎没有收到任何404错误,但是我的cookie没有保存--它们每次都会被重写。更奇怪的是,当我加载页面时,它至少会向发送90条GET请求,并在Google.com中存储4-5个SQLite数据库;evercookie网站只存储one。
我在生成的HTML页面中的代码如下:
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's possible for mismatching cookies.
// the best candidate is most likely the correct one这段代码的一部分写入我的文档,下面是输出(在我看来很好):
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那么,我的问题是如何防止发送到Google的90+请求?我不知道它为什么这么做。如果我一次在这个网站上有十个用户(这并不令人难以置信),那就是超过900(0)。你们中有谁知道为什么每次我刷新页面的时候饼干都会重置自己?,这正是我想要阻止的.
发布于 2011-03-24 20:45:15
好吧,别让我觉得蠢!结果是,代码开始时的ec.set()调用是在每个页面加载开始时设置cookie。所以,我调整了一些东西,而且,呃,现在起作用了。我不再向谷歌发送90个请求。
// 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
}
});https://stackoverflow.com/questions/5425133
复制相似问题