Saturday, 14 February 2015

CodeIgniter browser back button showing history fix

You may have noticed an issue while coding on CodeIgniter that even though you have destroyed the session values (invoking the $this->session->sess_destroy()) after logging out the page, the browser back button still takes you to your previous history page. Even though we may have made a provision to check empty session parameters and log out the page if the session has been destroyed, the browser back button still displays the previous pages that we have browsed.
The session check if we have used, tends to be working while refreshing the page, and doesn't let us browse new pages further. However, the back button lets us browse previous history items and it may raise an issue on privacy. User's private data may be visible to others too.
This occurs because the browser back button goes to the history when clicked.
We can prevent it by setting a header with no-cache. To prevent it, we should put the code given below in our index.php file with in the project.

header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");header("Cache-Control: no-store, no-cache, must-revalidate");

No comments:

Post a Comment