tags:

views:

86

answers:

2

I have a php form that submits data to a database. When the form has been successfully filled out and the data submitted, the form clears because of the page refresh. When the user hits the back button on the browser, the data comes back.

Is there a php function that will prevent the caching of this data?

+1  A: 

autocomplete="off" in the input fields of your forms?

gustavogb
I think the issue is not with autocomplete but rather the POSTED data. This data reappears in the form when the back button in the browser is used.
John R
+1  A: 

There isn't a reliable method, because the behaviour on back varies between browsers. Moreover, if someone has gone back through history, and you change what's happening, you are changing history. The metaphysical "woah!" of that aside, it's not a great idea.

What problem does this cause, apart from issues of from-resubmission? If form-resubmission is a problem then you need to deal with it in the case of a quick double-click on submit too anwyay. Include a hidden nonce value (UUIDs are good), store the nonce with your record of whatever it is the form does, and reject repeated nonces.

Jon Hanna
Hi Jon, the issue was the resubmission of the form. I've already contemplated what you are suggesting and just thought I'd ask if pragma no-cache would handle this for me. I generally prefer to take the easier way out, if there is one.
John R
pragma no-cache is deprecated, so look at the cache-control header. This aside, history records are different to web-caching (quite explicitly stated as such in the standard). Web-caching gives us ways to avoid either having to contact the server for a given URI or else having to download the entire contents. Browser history is a record of the state the browser was previously in, not the same thing at all.Always give http://www.ietf.org/rfc/rfc2616.txt a read over at least a couple of times every year. You can never be over-familiar with it.
Jon Hanna