Search code examples
phpcodeigniterhttp-redirectmobilemobile-website

Form being resend after going back


Here is a tricky question I've been trying to solve...

The issue happens on a mobile website. I use codeigniter to create a form, pass some values to the db and then redirect the user to the article that the user sent.

The problem is that when in Android WebView (which is a custom app), probably on other mobile devices too, so when the user hits the back button it resends the data and posts the article again. The article is being posted as many time as the user hits the back button, with no warning.

Any suggestions? Has someone had this issue?

Oh and by the way, if the whole history is erased (not sure if that is even possible, because its client side, and I don't fancy using javaScript for that) and the user hits back button, he will be taken out of the app, which I don't want to happen.


Solution

  • Pages that are loaded via POST will cause the browser to ask the user to resubmit the information to view the page resulting in the actions performed by that page happening again. If the pages is requested via GET and has variables in the querystring the same thing happens but silently (without the user being prompted to d it again).

    The best to work around this is to use the POST/REDIRECT/GET pattern. I used it in an example about processing payments that I wrote for Authorize.Net. Hopefully that points you in the right direction.