views:

584

answers:

4

I have six pages for a registration form in my PHP project.

In between any of the page if I press the back button from the explorer bar I get the error:

"Webpage has Expired". 

I am using $_POST to submit the data. I can't understand why this occurs?

+2  A: 

That message has to do with the way IE handles pages generated from POST data.

In general, to avoid this problem you have to make sure that in the back history, the user will never be able to land on a page that was generated from a POST request. As jspcal suggested, your POST response should be a redirect to another page requested by a GET. This is also considered best-practice since it reduces the risk of submitting a form twice.

Daniel Vassallo
A: 

Have you tried "$_GET"? This probably happens because the POST info comes from the page before and isn't really saved anywhere for longer than the transition of pages, whereas GET uses the URL to send the info, so the information is stored somewhere. I would see what happens with GET.

Moshe
In general you shouldn't submit a GET request, when your submitted form will leave side-effects, like inserting data in a database, or updating the browser cookies. In addition, GET variables in IE are limited in their total content length.
Daniel Vassallo
@Daniel - thanks. I didn't know any of that. Is it safe to use $_GEt when querying a database to show content to users? (READ ONLY, like a catalog of sorts)
Moshe
Yes, the best practice is to use GET for requests that display data without altering it, and POST for requests that may update or destroy data. (HTTP DELETE and PUT could be used for altering data too, but it's not common).
Alex JL
OK, thanks. Happy new year all.
Moshe
Thank you guys....
Nikhil
"Happy New Year"
Nikhil
+2  A: 

This always happens on certain browsers (you're probably using internet explorer) when you are trying to re-submit post data by going back in the browser history. Many browsers though (Firefox for example) give you the opportunity to submit the post data again when you go back in history.

Kristinn Örn Sigurðsson
+3  A: 

redirect the page after receiving the post:

$name = $_POST['name'];
...
header('Location: next.php');
jspcal
This is known as the PRG pattern:http://en.wikipedia.org/wiki/Post/Redirect/Get
Frank Farmer