In this tutorial, we are going to how to disable browser cache easily with Codeigniter. normally, When the user logout that time destroy the session but when we click to 'Go Back' button on own browser we can see the cached dashboard page. in that time we have faced that type of issue.

How to disable browser cache easily in Codeigniter, How to avoid browser cache, Disable cache in Codeigniter, Codeigniter cache

Config setting

We will configure prefix in config.php file on "application/config" directory. if you want to keep custom prefix different name then you can. This item allows you to set the filename/classname prefix when extending.

$config['subclass_prefix'] = 'MY_';

So, we will create MY_Output.php file on "application/core" directory. after then paste the below code in this file.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Output extends CI_Output {

    function nocache() 
    {
      $this->output->set_header("HTTP/1.0 200 OK");
      $this->output->set_header("HTTP/1.1 200 OK");
      $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
      $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
      $this->output->set_header("Cache-Control: post-check=0, pre-check=0");
      $this->output->set_header("Pragma: no-cache");
    }	
}
?>

Now, we will paste below code in the constructor function for first-time call the controller. because when call that method then it's every time disable browser cache.

$this->output->nocache();