This tutorial shows how to prevent browser caching easily in Codeigniter.

We face some kind of problems in real life when browser caches the data particularly when there are session data. Though we destroy session but still using back button users are able to view some data on browser. For example, when user logged in to the application they can easily go back to the login page using the browser’s back button. Again when user logged out of the application they can easily navigate to the previous page using browser’s back button.

So we can prevent browser caching data using some mechanism. So our below example will show how to achieve it easily in Codeigniter.
Here, my solution is to extend the Output library itself of the Codeigniter. So create the core class MY_Output which extends CI_Output and put the core class under “application/core” containing the following code


Now, all you have to do is call the method with the following code before you send any data to the browser.

I use to place this in my controller’s constructor for pages where user validation is required.

For example,


Thank’s for your patience. Please do not forget to leave a comment.

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

2 Thoughts on “How to disable browser cache easily in Codeigniter”

  • Hi,
    Great article! I’m trying to get this to work myself now at the moment. Our site uses PHP and CodeIgniter. Say a user is on a page, clicks “Logout”, then clicks back, Google Chrome will still display the page with the user’s data. Can this be prevented? Is Chrome doing anything outside what CodeIgniter can control? This is what I am trying to achieve. The above doesn’t seem to be working for me.

    Any tips or advice much appreciated!
    Thank you,

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.