473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

prevent caching of gd image

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
Nov 22 '05 #1
10 6293
It might not be just the PHP caching.. Did u check the IE and firefox
browser setting? in IE: Tools > Internet Options > Settings check if
the setting shows you how the caching is done.. this might help.

Nov 22 '05 #2
Try this in your import image script.

//**** Lots of headers to ensure the image is not cached.
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
//**** End of crappy headers.

It's not my own work, and I don't remember where I got it from but it
worked for me for a similar application.

Regards,

AD7six

Nov 23 '05 #3
Hi
Thanks: yes I've tried those headers. It still delivers a cached
version of the gd image unless the browser is idle for a minute or 2.

I'm going to contact my hosting provider and see if it's anything in the
server config.

What I don't understand is how it can go to the cached version of the
php script that generates the gd image even when the php script is
called via a URL with a unique querystring. (and it is: each time you
refresh and look at the source it is a different querystring.

regards
dave

AD7six wrote:
Try this in your import image script.

//**** Lots of headers to ensure the image is not cached.
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
//**** End of crappy headers.

It's not my own work, and I don't remember where I got it from but it
worked for me for a similar application.

Regards,

AD7six

Nov 23 '05 #4
"dave ches" wrote:
Thanks: yes I've tried those headers. It still delivers a cached
version of the gd image unless the browser is idle for a minute or 2.

I'm going to contact my hosting provider and see if it's anything in the
server config.

What I don't understand is how it can go to the cached version of the
php script that generates the gd image even when the php script is
called via a URL with a unique querystring. (and it is: each time you
refresh and look at the source it is a different querystring.


This sounds more like a browser problem than anything else. Can we have some
URLs please (i.e., the image script and the page that references it)? The
URL you posted earlier just points to a 404 error page.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Nov 23 '05 #5
dave ches,

URL would help investigations. I'm interested to here what the problem
is, when it is found.

What does a site like this http://www.delorie.com/web/headers.html have
to say about your headers?

Regards,

AD7six

Nov 23 '05 #6
Hi
Thanks for the interest.

delorie reports as follows:
for the file that references the image:

HTTP/1.1 200 OK
Date: Wed, 23 Nov 2005 14:59:42 GMT
Server: Apache/2.0.54 (Unix) mod_perl/1.99_17 Perl/v5.8.7
FrontPage/5.0.2.2635 PHP/4.3.11 mod_webapp/1.2.0-dev mod_python/3.1.4
Python/2.2.2 mod_ssl/2.0.54 OpenSSL/0.9.7d
X-Powered-By: PHP/4.4.1
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache
Last-Modified: Wed, 23 Nov 2005 14:59:42 GMT
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=iso-8859-1
for the file containing the image script:

HTTP/1.1 200 OK
Date: Wed, 23 Nov 2005 15:01:24 GMT
Server: Apache/2.0.54 (Unix) mod_perl/1.99_17 Perl/v5.8.7
FrontPage/5.0.2.2635 PHP/4.3.11 mod_webapp/1.2.0-dev mod_python/3.1.4
Python/2.2.2 mod_ssl/2.0.54 OpenSSL/0.9.7d
X-Powered-By: PHP/4.4.1
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache
Last-Modified: Wed, 23 Nov 2005 15:01:24 GMT
Connection: close
Content-Type: image/gif

AD7six wrote:
dave ches,

URL would help investigations. I'm interested to here what the problem
is, when it is found.

What does a site like this http://www.delorie.com/web/headers.html have
to say about your headers?

Regards,

AD7six


Nov 23 '05 #7
test URL please.

It's only the headers for the image file that are relavent, all _seems_
present and correct. Have you deleted your cache before testing?

Regards,

AD7six

Nov 23 '05 #8
Hi
The URL is www.companybattleships.com/index.php

The best way to show the unwanted caching is as follows.

1. open 2 new browsers.

2. in browser 1, go to www.companybattleships.com/index.php

3. in browser 2, go to www.companybattleships.com/callingpage.php

4. follow the link in browser 2. Observe that the image has changed.

5. refresh browser 1. The image has also changed. Great.

6. in browser 2, go back to www.companybattleships.com/callingpage.php

7. follow the link in browser 2 once again. Observe that the image has
changed again.

8. refresh browser 1. The image does not change. Problem.

cheers
dave

AD7six wrote:
test URL please.

It's only the headers for the image file that are relavent, all _seems_
present and correct. Have you deleted your cache before testing?

Regards,

AD7six

Nov 23 '05 #9
Well that's not an easy one, I can't tell if it's updating or not (on
any step) ;o).

Are you sure the image is being updated on every request? Compare the
behaviour of the below link when visiting multiple times & refreshing.
I think your headers are probably fine and the image is not being
updated.

http://www.noswad.me.uk/cachetest.html

Regards,

AD7six

Nov 23 '05 #10
Yes, the image is being updated every time you follow the link on

www.companybattleships.com/callingpage.php

you can see that because 6 additional black squares appear on the image
each time you follow that link.

But in your other browser (the one where you arrive at index.php with
not referer) you don't see the latest image: compare the 2 and the
black squares aren't there.

So why is the latest image not being displayed if the headers are in order?

In the example you send, the 2 images:
This image does not set any extra HTTP Headers
and
This image has headers set to prevent caching

are identical, so doesn't that just confirm that the headers don't do as
they are supposed to when drawing in gd images?

regards
dave

AD7six wrote:
Well that's not an easy one, I can't tell if it's updating or not (on
any step) ;o).

Are you sure the image is being updated on every request? Compare the
behaviour of the below link when visiting multiple times & refreshing.
I think your headers are probably fine and the image is not being
updated.

http://www.noswad.me.uk/cachetest.html

Regards,

AD7six

Nov 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Griffiths | last post by:
Hi all Very new to JavaScript, I am trying to cache a number of images as the page loads, is there a max number of images or memory usage before the browser stops caching. My PC has 1G ram so...
14
by: Ludwig77 | last post by:
I read that there are some tags that can be entered in a web page's meta tags in order to prevent web bot searching and indexing of the web page for search engines. What is the tagging that I...
5
by: R. Ian Lee | last post by:
I have an ASP.NET page that spawns a popup window using javascript's window.open. This works fine. It pops up, you enter some data, press save and everything saves as it should. But, if you...
4
by: Jake | last post by:
Does cookieless session state (with the sessionid embedded into the url) interfere with the browser's retrieval of cached images from one session to the next? Does the sessionid embedded into the...
0
by: Frankie | last post by:
When I want to prevent a page from being cached, I have been using the following directive: <%@ OutputCache Location="none" %> I have also seen a few other methods recommended to prevent page...
1
by: Giggle Girl | last post by:
Hello, I am helping to design a web application that uses 167 little icons on various pages in a framed environment. As is, the app loads each icon on a page by page basis, and if an image...
1
by: Ronald S. Cook | last post by:
I have an ASPX page wherein I receive an ID of a file to play. http://localhost/fwi/mediaplayer.aspx?id=3 When I go to a browser and type in the above, it works fine. But when I change the 3...
9
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
I'm working on a litigation web app where users will review images of case documents. One of the requirements is that we either prevent the images from being cached on the clients machine (in temp...
0
by: helveticus | last post by:
I have a master/details configuration that includes multiple user controls. The details page is configured to cache data via VaryByCustom. This works fine. One of the user controls contains an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.