fresskoma
fresskoma

Reputation: 25781

Prevent Internet Explorer 8 from caching form data

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.

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" />

And the form tag like this:

<form action="action uri" method="post" autocomplete="off">

Upvotes: 0

Views: 1855

Answers (2)

Diogo
Diogo

Reputation: 39

you can put this code inside your HTML HEAD:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

or use Fire's suggestion in your PHP code.

Upvotes: 0

fire
fire

Reputation: 21531

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

Upvotes: 2

Related Questions