Re: Is it possible to stop an image from being cached?

From: Date: Thu, 26 Jul 2007 23:15:15 +0000
Subject: Re: Is it possible to stop an image from being cached?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-259610@lists.php.net to get a copy of this message
On 7/27/07, Chris Aitken <chris@thewebhub.com.au> wrote:
header('Cache-Control: no-store, no-cache, must-revalidate, Post-Check=0, Pre-Check=0'); brian
That's HTTP/1.1 only, but this is what I got from PHP site: <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> But wouldn't that make every image on the page be uncached and reloaded each time? Not very efficient if the shell of the site keeps getting loaded if only 1 or 2 images need to be forced. Regards Chris Aitken The Web Hub Designer and Programmer Phone : 02 4648 0808 Mobile : 0411 132 075
Yes, that depends on which way it is used, I wouldn't recommend loading images from the database that don't get changed... And you can of course also use an if-statement/switch-statement/in_array function in your image.php script, like this: $img = $_GET['img']; if($img == "test_a.jpg" || $img == "test_b.jpg") { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past } OR: $img = $_GET['img']; switch($img) { case "test_a.jpg": case "test_b.jpg": header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past } OR: $img = $_GET['img']; $noncached_images = array("test_a.jpg","test_b.jpg"); if(in_array($img,$noncached_images)) { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past } Tijnema -- Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

« previous php.general (#259610) next »