

<!DOCTYPE html>
<html>
<head>
<title>js23.html</title>
<script type="text/javascript">
var today = new Date();
var expireDay = new Date();
var msPerMonth = 24*60*60*1000*31;
expireDay.setTime(today.getTime()+msPerMonth);
document.cookie = "name=allen;expires="+expireDay.toGMTString();
document.writeln("cookie 已经在硬盘上","<br>");
document.writeln("内容是:"+ document.cookie,"<br>");
document.writeln("有效日期:"+expireDay.toGMTString(),"<br>");
</script>
</head>
<body>
</body>
</html>
结果:
cookie 已经在硬盘上
内容是:name=allen
有效日期:Fri, 31 Aug 2012 13:50:30 UTC
======
我们来到 C:\Users\allen\AppData\Local\Microsoft\Windows\Temporary Internet Files, 发现一个叫做
js/的文件。但是他的实际名称却是: GSL2NE44.txt
打开后的内容如下:
name
allen
localhost/test/js/
1600
2505791232
30246783
1930102863
30240547
*
我们问个问题:我们知道 Session 是通过 cookie 实现的。那为什么session 信息没有存在硬盘上呢?
Answer: 这是因为有两种类型的cookie,持久性 cookie 和 会话 cookie。
1)持久性 cookie会被存储到客户端的硬盘上
2) 会话 cookie: 不会存储到客户端硬盘上,而是放在浏览器进程所处的内存当中,当浏览器关闭该会话 cookie 就被销毁了。