0

I have a Codeigniter 2.2 project. without no changing in the code my browser somehow holding cache for previous logged user. If i reload with clearing cache then it shows currently logged user.

I have added My_Output core controller. and added $this->output->clear_cache() in the logout function. I have also added

 <IfModule mod_headers.c>   
Header set Cache-Control "no-cache, no-store, must-revalidate"  
Header set Pragma "no-cache"    
Header set Expires 0 
</IfModule> 

in my .htaccess file. Still same problem

Zendie
  • 1,176
  • 1
  • 13
  • 30

2 Answers2

3

You have to send the proper headers to the client.

$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");
lalit mittal
  • 444
  • 3
  • 8
  • where should I put these lines? – tarek nasif Sep 27 '19 at 17:23
  • 1
    @tareknasif "if you have created a MY_Controller.php file and class in your core folder, you can add it in the public function __construct() .... " If not then you can add it to every controller that you will won't to prevent that caching's __construct() function. – Developer Kwame Dec 02 '19 at 01:49
0
     $this->CI =& get_instance();   
     $this->CI->session->sess_destroy();
     $this->cache->clean();
     redirect(base_url());
jones
  • 749
  • 7
  • 34
  • 2
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Dharman Sep 27 '19 at 13:10