Reputation: 43
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?
Upvotes: 4
Views: 1681
Reputation: 113282
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.
Upvotes: 1