473,473 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to keep from cacheing images...

I have a script that outputs images directly using the 'image' functions.
I have googled quite a bit but cannot seem to find the correct method of
sending headers to keep the images from being cached... these are dynamic
images.

Norm
Jul 17 '05 #1
7 1775
Norman Peelman wrote:
I have a script that outputs images directly using the 'image'
functions.
I have googled quite a bit but cannot seem to find the correct method of
sending headers to keep the images from being cached... these are dynamic
images.


This should do it:

header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2
"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10**************@216.128.74.129...
Norman Peelman wrote:
I have a script that outputs images directly using the 'image'
functions.
I have googled quite a bit but cannot seem to find the correct method of
sending headers to keep the images from being cached... these are dynamic images.


This should do it:

header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/


Still not working: I want to do this...

HTML page
-------------

<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
</BODY>
</HTML>
myimage.php can return a random image regardless of what image=21 is set
to and I want to see different images on the same page where the
<IMG SRC="http://my.domain.com/myimage.php?image=21"> tag appears more than
once. I have no option to change the image=21 value after it is inserted
into the html. I keep seeing the same image for all occurances. Refreshes
will change the image but that is really not the desired effect.

Norm
Jul 17 '05 #3
Norman Peelman wrote:
"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10**************@216.128.74.129...
Norman Peelman wrote:
> I have a script that outputs images directly using the 'image'
> functions.
> I have googled quite a bit but cannot seem to find the correct method
> of sending headers to keep the images from being cached... these are dynamic > images.


This should do it:

header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');

Still not working: I want to do this...

HTML page
-------------

<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
</BODY>
</HTML>
myimage.php can return a random image regardless of what image=21 is set
to and I want to see different images on the same page where the
<IMG SRC="http://my.domain.com/myimage.php?image=21"> tag appears more
than
once. I have no option to change the image=21 value after it is inserted
into the html. I keep seeing the same image for all occurances. Refreshes
will change the image but that is really not the desired effect.


It's not going to work. The browser will see that it's supposed to display
the same image http://my.domain.com/myimage.php?image=21 four times so it's
only going to request the image once and display it four times.

If you want all four images to be different why don't you do something like
eg:

<IMG SRC="http://my.domain.com/myimage.php?image=21&foo=1">
<IMG SRC="http://my.domain.com/myimage.php?image=21&foo=2">
<IMG SRC="http://my.domain.com/myimage.php?image=21&foo=3">
<IMG SRC="http://my.domain.com/myimage.php?image=21&foo=4">

The "foo" value doesn't need to mean anything, but it will mean the browser
has to download all 4 instances as the URLs are all unique.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #4
"Norman Peelman" <np******@cfl.rr.com> escreveu na mensagem
news:ys*******************@twister.tampabay.rr.com ...
I have a script that outputs images directly using the 'image' functions. I have googled quite a bit but cannot seem to find the correct method of
sending headers to keep the images from being cached... these are dynamic
images.

Norm


Strangely i have the opposite situation, my site (http://ntg.docaj.net)
seems to be trying to fetch the images on every page reload (refresh)
despite the fact that the image name is always the same (check the ranking
on the right side for instance, the red and green png images are always
download on every refresh).

How to prevent it? using clients cache?

Thanks,
RootShell
Jul 17 '05 #5
Add a random query string at the end of your URL and that should do it.
What is happening is that your browser is caching, not necessarily the
server.

before you output anything try this as well:

clearstatcache();

then add your headers as Chris Hope suggested.. then in your HTML do this:

<IMG SRC="http://mydomain.com/myimage.php?image=21&junk=<?= randstring(16)
?>">

Where randstring() is a function you write that outputs a random
alphanumeric string of a-zA-Z0-9

Phil
"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:nl*********************@twister.tampabay.rr.c om...
"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10**************@216.128.74.129...
Norman Peelman wrote:
I have a script that outputs images directly using the 'image'
functions.
I have googled quite a bit but cannot seem to find the correct method of sending headers to keep the images from being cached... these are dynamic images.
This should do it:

header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/


Still not working: I want to do this...

HTML page
-------------

<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
<IMG SRC="http://my.domain.com/myimage.php?image=21">
</BODY>
</HTML>
myimage.php can return a random image regardless of what image=21 is set
to and I want to see different images on the same page where the
<IMG SRC="http://my.domain.com/myimage.php?image=21"> tag appears more

than once. I have no option to change the image=21 value after it is inserted
into the html. I keep seeing the same image for all occurances. Refreshes
will change the image but that is really not the desired effect.

Norm

Jul 17 '05 #6

"RootShell" <AN***************@Netcabo.ptANTISPAM> wrote in message
news:40***********************@news.telepac.pt...
"Norman Peelman" <np******@cfl.rr.com> escreveu na mensagem
news:ys*******************@twister.tampabay.rr.com ...
I have a script that outputs images directly using the 'image'

functions.
I have googled quite a bit but cannot seem to find the correct method of
sending headers to keep the images from being cached... these are dynamic images.

Norm


Strangely i have the opposite situation, my site (http://ntg.docaj.net)
seems to be trying to fetch the images on every page reload (refresh)
despite the fact that the image name is always the same (check the ranking
on the right side for instance, the red and green png images are always
download on every refresh).

How to prevent it? using clients cache?


That's correct behavior. The browser is supposed to revalidate all files
when the user requests a page refresh.
Jul 17 '05 #7
"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:ys*******************@twister.tampabay.rr.com ...
I have a script that outputs images directly using the 'image' functions. I have googled quite a bit but cannot seem to find the correct method of
sending headers to keep the images from being cached... these are dynamic
images.

Norm


It seems my second post got lost somewhere - here it is again. Let's say I
have a HTML file like so:

<HTML>
<HEAD>
<TITLE>Image Test</TITLE>
</HEAD>
<BODY>
<IMG SRC="http://www.mydomain.com/myscript.php?img=21">
<IMG SRC="http://www.mydomain.com/myscript.php?img=21">
<IMG SRC="http://www.mydomain.com/myscript.php?img=21">
<IMG SRC="http://www.mydomain.com/myscript.php?img=21">
</BODY>
</HTML>

---

Now, 'myscript.php' is coded such that depending on the value of 'img' it
can return a random image (using the PHP/GD 'image' functions). I would
like to be able to have the above HTML page display four random images upon
each view/refresh. I do not have the ability to alter the SRC attribute as
it may appear only once or ten times in a single web page, I don't know.
Currently I do see random images upon each refresh but all four images
displayed are the same. Is there no headers that I can send that would tell
the browser to ask for the <IMG> each time it encounters it.

So, in short, I know that my script works fine. There just seems to be the
issue of not being able to tell the browser to send a seperate request for
each <IMG> encountered. That is my desired effect.

Thank you,

Norm
Jul 17 '05 #8

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

Similar topics

10
by: Clive Backham | last post by:
I tried posting this on comp.infosystems.www.misc, but that group appears to get very little traffic. So now I'm trying here. If there is a more appropriate group, please let me know. I'm...
12
by: Sunny | last post by:
Hi, I need to download some web pages from a web server (most of them are not static html, but .asp pages). The content (I.e. the pure html) in the pages are not changed very often, so I'll...
8
by: roy anderson | last post by:
Hey all, Thought I had this figured out a week ago, but evidently not. Basically when I publish a site in 2.0, the images aren't cacheing? For instance, let's say I created a page with a...
3
by: urs.eichmann | last post by:
Hello, several parts of the pages of my ASP.NET 2.0 site are mainly static, such as a treeview with all the product categories, a menu bar, the company header and so on. But they also have a...
3
by: visu | last post by:
I am currently working on my personl website a completely DB driven web application. in that i ve updating the images thru my admin panel .. but i am getting the old images not the update one when...
4
osward
by: osward | last post by:
I had made a table colum sortable and paging the table, following are the code // Display Event List echo "<center>"._EVENTLIST."</center><br>"; $now = Date(Y-m-d); // sort table...
1
by: Eddy Jones | last post by:
I'm looking to implement the Enterprise Cacheing block as a plugin to an ASP page. I expect this page to be hit many many times a second and I'm concerned about thread safety. One of the 'bullet...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.