Forum Moderators: coopster

Message Too Old, No Replies

Controlling the "Back" and "Refresh" buttons

in the browser

         

neophyte

12:43 am on Mar 25, 2008 (gmt 0)

10+ Year Member



Hello All -

Many projects I'm involved with have form sections (more than one form pages). When a user completes one form page there's a "Next >" SUBMIT button which, when pressed, triggers a validation routine - if everything passes validation, the user is served the next page.

When a user is on the second (or third, or fourth) page of a form section, each of these pages also has a "< Back" SUBMIT button. if they click that, all information in the current page is saved to $_Sessions and the user is transported back to the previous page without any information loss or anything getting screwed up.

My problem, is that when a user has already submitted a form and then presses the back or refresh button on the browser, funny things begin to happen to the information previously submitted - Sessions get over-written, etc. I think this is because the back button re-displays get vars in the URL line from the previous page.

Anyway, I think that I can deal with this if there's a way that I can detect that the browser back button or refresh button has been pressed: if I can detect this, then maybe I can use some other function to strip out any get vars in the URL before the page is re-displayed - I don't know if that's possible, but it's a thought.

So... is there a way in PHP to detect the activation of the back and refresh buttons?

If not, is there a way to de-activate these buttons when a user is working within a form section (I know this isn't a very good "usability" choice, but I need a fall-back position if there's no way to detect these buttons being pressed).

All advice greatly appreciated.

Neophyte

vincevincevince

12:51 am on Mar 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should be using POST for forms which add to or update the database, not GET. Nevertheless, you can put a timestamp into the URLs you issue (i.e. by GET), and also store it in the $_SESSION.

blahblah.php?arg=val&time=1123434235

Then, if you are presented with a page load you can test as follows:

if ($_SESSION[time]!=$_GET[time])

And then erase the old $_GET values:

$_GET="";

neophyte

2:21 am on Mar 25, 2008 (gmt 0)

10+ Year Member



Vincevincevince -

Just to clarify, I am using POST to actuate the next/back buttons on my form. I'm only using GET for page-specific settings.

Very interesting strategy you offered, though! I'll try it and see if it solves my problems/angst.

Thanks again!

vincevincevince

2:24 am on Mar 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using $_POST then the user should not be able to go back without a warning coming up and the page being reloaded.