How To Disable Browser Cache in Codeignitor

In my Project, I had a big issue about cache. I want to remove browser cache because some web pages takes browser cache to load. Therefore I wrote a library script for codeignitor to disable browser cache.

Create cache_lib.php in application/libraries and paste below code in it.

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

class cache_lib extends CI_Output {

    function nocache()
    {
        $this->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
        $this->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
        $this->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
        $this->set_header('Pragma: no-cache');
    }

}
Now You Can Import nocache method using following line of code.

$this->output->nocache();

Happy Coding !

0 comments:

Post a Comment

Ask anything about this Tutorial.