In a normal web app w/ login and secure data, what is an easy way to secure that data and prevent it from being seen by using the browser's back button, once a user logs out?
You can-not actually disable the browser back button. However, you can do magic using your logic to prevent the user from navigating back which will create an impression like it is disabled.
Use history. pushState() event and onpopstate property of the WindowEventHandlers to stop back navigation on browsers. The following code snippet disables the browser back button using JavaScript. Place this code into the web page where back navigation to be restricted.
On the login screen, in PHP, before rendering the view, you need to check if the user is already logged in, and redirect to the default page the user should see after logged in. Similarly, on the screens requiring login, you need to check if the user is not logged in and if not, redirect them to the login screen.
A back button in the browser lets you back-up to the copies of pages you visited previously. The web browser's back and next buttons work well with web sites that provide information that changes infrequently, such as news and shopping web sites.
Here's a useful browser caching guide.
You want to set the cache-control and expiration date headers (setting a date in the past), e.g.
Cache-Control: no-cache
Expires: Fri, 31 Dec 1998 12:00:00 GMT
Cache control headers (Expires, Cache-Control, ETag) will generally prevent the caching of the page, forcing the browser to request a new copy at which point you can check the session status. They are sometimes ignored in the interests of "performance" though.
There are two Javascript approaches that could help you:
Both of these are likely to have a pretty horrid effect on usability though.
Although there are some very reasonable solutions to this (cache control headers, javascript, etc), you need to realise that once you have sent something to a client, it is out of your control. You cannot guarantee that the client will treat the data in the way you would like.
For example:
Sorry :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With