1

I am using codeIgniter 2.1.4 in my application. If am in a page that require authentication. Then I logout after logout if I use browser back button it will get me back to the secured page. I can only view the page. If I refresh or click on any link it will redirect me to the login page.

I think it's a cache issue? But I am not sure.

serenesat
  • 4,611
  • 10
  • 37
  • 53
Bikram Pahi
  • 1,107
  • 1
  • 12
  • 33
  • 1
    check http://stackoverflow.com/questions/10418964/codeigniter-back-button-after-logout?rq=1#answer-10439679 – oikonomopo Jun 04 '15 at 12:33
  • 1
    @oikonomopo fun fact: Safari on iPad (probably all iDevices) doesn't obey. Apple seems to be too cool to follow the rules. – MonkeyZeus Jun 04 '15 at 12:35
  • ok, thanks to @MonkeyZeus consider also this: http://stackoverflow.com/questions/5297122/preventing-cache-on-back-button-in-safari-5/5305905#5305905 – oikonomopo Jun 04 '15 at 12:51

3 Answers3

2

paste $this->output->nocache(); in your __construct() function after parent::__construct();

Kavin Smk
  • 808
  • 11
  • 37
1

Include these headers in the constructor function of the controller to prevent the caching of previous page

If you want the Code Igniter's way of doing it include the below code

$this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'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',false);
$this->output->set_header('Pragma: no-cache');

PHP's way of doing it use the below lines of code

header("cache-Control: no-store, no-cache, must-revalidate");
header("cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
Abhinav
  • 8,028
  • 12
  • 48
  • 89
0

You can prevent the client's browser from caching the site by adding

<meta Http-Equiv="Cache-Control" Content="no-cache">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="0"> 

into your HTML header.

Yami
  • 1,405
  • 1
  • 11
  • 16