为什么不能使用mootools更改cookie值?
如果我在php中设置了cookie值,我将无法使用mootools更改cookie值。
为什么失败?是mootools的bug吗?
<?php
setcookie('drres','hello');
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js"></script>
<script type="text/javascript">
function drres_cookie_read(){
alert(Cookie.read('drres'));
}
function drres_cookie_write(){
Cookie.write('drres','world');
alert(Cookie.read('drres')); // result is "hello" not "world",why?
}
</script>
<button onclick="drres_cookie_read()">read</button>
<button onclick="drres_cookie_write()">write</button>发布于 2012-12-30 18:08:48
您不能在同一实例/页面中设置和访问cookie。浏览器将根据从服务器发送到browser.Technically的标头来识别cookie并存储它。您不能更新cookie,只能用同名的新cookie覆盖它。在设置setcookie('drres','world');以更新值之后,您必须执行重定向或刷新。
发布于 2012-12-30 17:24:32
我明白了。我认为这是一种跨脚本保护。您不能写入或删除服务器设置的cookies。(否则,例如,您将能够覆盖登录cookie)。
https://stackoverflow.com/questions/14089504
复制相似问题