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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/27/07, Chris Aitken <chris@xxxxxxxxxxxxxxxx> 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux