php gd prevent caching

This is a discussion on php gd prevent caching within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi I want to stop a gd generated image from being cached. It is called into index.php file as ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-22-2005
dave Cheseldine
 
Posts: n/a
Default php gd prevent caching

Hi
I want to stop a gd generated image from being cached.

It is called into index.php file as follows:

<image src =
"http://www.daveches.co.uk/importimage/importimage.php?x=$randomNumber"
alt = "battle area" usemap="#battlegrid" border="0">

(importimage4real.php contains the gd functionality that load and modify
the image).

The random number querystring in the code above is an attempt to trick
the browser into thinking the image is different from what it has in
its cache. But still it displays its cached version of the image.

I have tried every "stop caching" header I can think of in both
index.php and importimage.php, set expires to a time in the past and all
the rest. Still, refresh the browser: you get the cached, not the
latest, image (same in ie6 and Firefox). After a few minutes something
expires and you do get the latest version by Refreshing, but this is no
good for my application.

Is it possible that some settings on my hosting company's server are
overwriting any changes I can make?

dave Cheseldine
Reply With Quote
  #2 (permalink)  
Old 11-25-2005
Mike Willbanks
 
Posts: n/a
Default Re: php gd prevent caching

dave,

> I have tried every "stop caching" header I can think of in both
> index.php and importimage.php, set expires to a time in the past and all
> the rest. Still, refresh the browser: you get the cached, not the
> latest, image (same in ie6 and Firefox). After a few minutes something
> expires and you do get the latest version by Refreshing, but this is no
> good for my application.


Are you sure you are using all of the correct headers?

header('Pragma: no-cache');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

Mike
Reply With Quote
  #3 (permalink)  
Old 11-25-2005
Connector5
 
Posts: n/a
Default Re: php gd prevent caching

And also, dont use the same expiry/modified on each load:


// Expire the image 1 year before it's being viewed, and make it modified 2
minutes ago
header("Last-Modified: " . date(DATE_RFC822, time() - 120));
header("Expires: " . date(DATE_RFC822, time() - (3600 * 24 * 365)));


It's trivial and minor, but you never know.


One final option: Use a bit of javascript onload to refresh the image on
the client side.



"Mike Willbanks" <pencap@gmail.com> wrote in message
news:tduhf.729$DW6.59@fe03.lga...
> dave,
>
> > I have tried every "stop caching" header I can think of in both
> > index.php and importimage.php, set expires to a time in the past and all
> > the rest. Still, refresh the browser: you get the cached, not the
> > latest, image (same in ie6 and Firefox). After a few minutes something
> > expires and you do get the latest version by Refreshing, but this is no
> > good for my application.

>
> Are you sure you are using all of the correct headers?
>
> header('Pragma: no-cache');
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Cache-Control: private",false);
> header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
>
> Mike



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:43 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0