Nikhil
Nikhil

Reputation: 41

Error - Web Page Has Expired in PHP?

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?

Upvotes: 2

Views: 4626

Answers (5)

rroche
rroche

Reputation: 1272

The real answer is "If you hit the back button, the browser doesn't send the POST request you originally sent when you first visited that page", what you might want to do if you are doing a multi-step form is either do it with AJAX, or use GET instead of POST.

Upvotes: 0

Daniel Vassallo
Daniel Vassallo

Reputation: 344431

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.

Upvotes: 4

jspcal
jspcal

Reputation: 51914

redirect the page after receiving the post:

$name = $_POST['name'];
...
header('Location: next.php');

Upvotes: 3

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.

Upvotes: 2

Moshe
Moshe

Reputation: 58097

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.

Upvotes: 0

Related Questions