Page 1 of 1
How to stop user from going back to a previous page
Posted: Mon Apr 03, 2006 7:11 am
by raghavan20
Are there any scripts or tutorials available to stop user from going back to a previous page. This has to be done since I am working transaction related pages and I do not want the user to go back and he/she should mandatorily use links to modify content submitted.
Re: How to stop user from going back to a previous page
Posted: Mon Apr 03, 2006 7:48 am
by Roja
raghavan20 wrote:Are there any scripts or tutorials available to stop user from going back to a previous page. This has to be done since I am working transaction related pages and I do not want the user to go back and he/she should mandatorily use links to modify content submitted.
The solution is a pattern called "PRG".
http://www.theserverside.com/patterns/t ... d_id=20936
In a nutshell, you post, then redirect, then get the results. Then if they hit back, they end up at the redirect, which puts them exactly where they were - without changes occuring a second time.
Posted: Mon Apr 03, 2006 8:30 am
by RobertGonzalez
Isn't trying to prevent the use of back a little unreliable. What if a user holds their back button and goes back three or fours pages (like I do from time to time)?
Posted: Mon Apr 03, 2006 8:45 am
by Roja
Everah wrote:Isn't trying to prevent the use of back a little unreliable. What if a user holds their back button and goes back three or fours pages (like I do from time to time)?
If they hold it, the browser behaviors (so far, in all the majors) won't go further back. As soon as the first hits, it resolves to the redirect, and subsequent "back" just go to the last one.
However, if the user manually chooses to go back multiple pages (like with the history dropdown), then yes, it will go back that far.
To prevent *that* as well, use a one-time token in the form, so that the form won't process twice.

Posted: Mon Apr 03, 2006 8:59 am
by patrikG
in addition to Roja's solution: if the data on the form is sensitive and should, ideally, be only submitted once, prevent it from being cached. Example:
header()
Posted: Mon Apr 03, 2006 10:12 am
by RobertGonzalez
Roja wrote:Everah wrote:Isn't trying to prevent the use of back a little unreliable. What if a user holds their back button and goes back three or fours pages (like I do from time to time)?
If they hold it, the browser behaviors (so far, in all the majors) won't go further back. As soon as the first hits, it resolves to the redirect, and subsequent "back" just go to the last one.
What I was saying with this is that in IE, if you click and hold the back button it lists all of the last X number of pages you've been to. In Firefox, there is the big back button (one back) and the little back button (lists all backs). In Opera there is the same functionality. Not sure of the others. So, like just a few minutes ago, I was able to go back like 10 pages at a pop in Firefox. How do you prevent that browser functionality?
In response to the original question, one thing to consider is the placement of "Back" and "Forward" links on the pages you are having your users use. That way they can go "back" by always going forward. Maybe even including a message to not use the browsers back button. Of course, removing the cache for the pages could do the trick also, until someone reloads a page that was cleared from the cache already.
Posted: Mon Apr 03, 2006 10:17 am
by patrikG
Everah wrote:Of course, removing the cache for the pages could do the trick also, until someone reloads a page that was cleared from the cache already.
Yup. And to when they try to reload the page, they have to manually confirm via popup that they really want to reload the page.
Posted: Mon Apr 03, 2006 10:19 am
by Roja
Everah wrote:What I was saying with this is..
Thats a much better way to phrase it. I was trying to capture the difference between clicking back, and the more indepth history system.
In a nutshell, to prevent it, you have to code your form specifically to do so.
Posted: Wed Apr 05, 2006 7:43 am
by raghavan20
thanks for your answers. how to clear the cache or the history stored in the browser???
Posted: Wed Apr 05, 2006 7:44 am
by John Cartwright
header()
Code: Select all
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Posted: Thu Apr 06, 2006 5:36 am
by raghavan20
As far as I could remember and from the PHP manual, JCart that code will not cache a page and user has to refresh the page to see it but what I am asking is to stop user from going any previous pages he/she visited.