防止Internet Explorer 8缓存表单数据 [英] Prevent Internet Explorer 8 from caching form data
问题描述
我目前面临的问题是IE8决定缓存一个(隐藏的)表单字段,我在其中写入随机生成的哈希,该哈希也存储在会话中.如果以表单发送的哈希值等于存储在会话中的哈希值,则该表单请求有效.
I'm currently facing the problem that IE8 decides to cache a (hidden) form field into which I write a randomly generated hash, which is also stored in the session. If the hash sent in the form equals the hash stored in session, the form request is valid.
但是因为IE缓存了这些值,所以以表格形式发送的值不同于会话中存储的值.如何防止这种情况发生?我在字段和<form>
元素中都尝试了autocomplete="off"
.
But because IE caches those values, the value sent in the form differs from what is stored in the session. How can I prevent this from happening? I tried autocomplete="off"
in both the field and the <form>
element..
隐藏的输入字段如下所示:
The hidden input field looks like this:
<input type="hidden" name="hash" value="hash inserted here" autocomplete="off" />
还有这样的表单标签:
<form action="action uri" method="post" autocomplete="off">
推荐答案
autocomplete
与它无关,页面本身被缓存在浏览器中.
autocomplete
has nothing to do with it, the page itself is cached in the browser.
您可以设置一些标头来禁用此功能:
You can set some headers to disable this:
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
这篇关于防止Internet Explorer 8缓存表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!