可怕的Evercookie和CakePHP
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了可怕的Evercookie和CakePHP,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2633字,纯文字阅读大概需要4分钟。
内容图文
![可怕的Evercookie和CakePHP](/upload/InfoBanner/zyjiaocheng/769/0f5ad3e29222430cb795b921087aaafa.jpg)
所以我试图在cakePHP网站上实现evercookie,但是我得到了一些非常非常奇怪的结果.我刚刚将代码文件复制并粘贴到我的app / webroot目录中,我似乎没有得到任何404错误,但我的cookie没有保存 – 他们每次都被重写.甚至更奇怪的是,当我加载页面时,它向Google.com发送至少90个GET请求,并在Google Chrome中存储4-5个SQLite数据库; evercookie网站只存储一个.
我生成的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).你有没有想过为什么每次刷新页面时cookie都会重置?这正是我想要阻止的.
解决方法:
好吧,我不觉得傻!事实证明,代码开头的ec.set()调用是在每个页面加载开始时设置cookie.所以,我调整了一些东西,呃,它现在正在运作.而且我不再向Google发送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
}
});
内容总结
以上是互联网集市为您收集整理的可怕的Evercookie和CakePHP全部内容,希望文章能够帮你解决可怕的Evercookie和CakePHP所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。