CodeIgniter Forums
PHP Codeigniter is showing the cache when i press the back button after I logout - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: PHP Codeigniter is showing the cache when i press the back button after I logout (/thread-53611.html)



PHP Codeigniter is showing the cache when i press the back button after I logout - El Forum - 07-31-2012

[eluser]Unknown[/eluser]
After I logout from my app, when I press the back button, all of the login options for the user is still showed on the page.

After I login, when I press the back button it will show the logout version of the page.

I tried setting this in my logout controller

Code:
function logout() {
    $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");
    $this->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    $this->tank_auth->logout();
    redirect(subdomain() . 'home');
}

But the cache is still there when i press the back button. How can i fix this?

-----UPDATE------

I think caching is not the problem here, I disabled caching in chrome in developer settings but my browser is still going to the secured page after logout when i press the back button.

So caching is not the problem..

----UPDATE2------

Caching is the problem! I fixed this by putting this code in the index.php file of codeigniter

Code:
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");

So the problem is solved!


PHP Codeigniter is showing the cache when i press the back button after I logout - El Forum - 07-31-2012

[eluser]WanWizard[/eluser]
That isn't PHP or CI's fault, it's standard browser functionality.

Back means "back to the previously loaded page", not "re-fetch the previous URL I visited".

Using the back button shouldn't be an issue, the user has already seen the page, and anything action done on the page should be caught by your applications authorisation system.

Disabling cache for all pages isn't really a good idea, it will introduce a serious performance hit.