Skip to content

Instantly share code, notes, and snippets.

@og-shawn-crigger
Created April 5, 2012 07:38
Show Gist options
  • Save og-shawn-crigger/2308795 to your computer and use it in GitHub Desktop.
Save og-shawn-crigger/2308795 to your computer and use it in GitHub Desktop.
CodeIgniter Snippet to Force No Cache Headers
<?php
function set_nocache_headers()
{
$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', time()).' 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");
}
@og-shawn-crigger
Copy link
Author

Simple snippet I use when working with Ajax post data to make sure the result is not cached when that is needed. ( IE Image Editing )

@dejurin
Copy link

dejurin commented May 14, 2017

why better
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
than
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
?

@fahadrana31
Copy link

hi!

i am facing this problem with my cart in codeigniter. can you tell me how can i implement on my website?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment