How to stop user from going back to a previous page
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
How to stop user from going back to a previous page
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
The solution is a pattern called "PRG". http://www.theserverside.com/patterns/t ... d_id=20936raghavan20 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.
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.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)?
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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?Roja wrote: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.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)?
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.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact: