views:

847

answers:

3

Hi there

In my web-application I'm using $_SESSIONS but sometimes, when the users hits the backspace key he gets "Webpage has expired" message.

Why is happening this? What to do to avoid this?

+5  A: 

This doesn't have anything to do with $_SESSION variables, it has to do with you transferring information between pages using POST method. If you want to avoid it you need to use GET method instead of POST.

Chad Birch
Also, it's only something IE displays as far as I know.
Matt
Chrome too I believe
Rob
Firefox displays a dialog informing you that you need to re-send information to view this page (or something along those lines) with options to Re-sent or Cancel.
R. Bemrose
You shouldn't blindly replace a POST request by a GET request.http://tools.ietf.org/html/rfc2616#section-9.1.1 :"In particular, the convention has been established that the GET andHEAD methods SHOULD NOT have the significance of taking an actionother than retrieval."
VolkerK
As a side note, to avoid this, once you finish your POST processing, redirect to another page.
R. Bemrose
Well, you shouldn't blindly do it, but he hasn't supplied any detail about what functionality is actually causing this. We can't really assume that replacing it with GET is either a good or bad idea. If it's something that the user is regularly trying to go "Back" to, my guess is that it's something like search results. That's why I went ahead and suggested a replacement with GET. We really can't know unless he tells us though.
Chad Birch
+1  A: 
VolkerK
+1  A: 

Like Chad said, that's the result of going back to a page that was the result of a POST request. And like the comments said, you can't just replace a POST with a GET, because that's a bad idea for a variety of reasons.

However, you can combine the two: let the request be a POST, but issue a Location header redirect, which the browser will then execute as a GET. To the user this will look like a single operation, but to the browser it will be a POST followed by a GET, which effectively eliminates this issue.

Rytmis