| re: How to force browser to reload image from server?
On Thu, 23 Sep 2004 09:05:34 +0200, Simon Stienen
<simon.stienen@news.slashlife.de> wrote:
[color=blue]
>Chung Leong <chernyshevsky@hotmail.com> wrote:[color=green]
>> "Martin" <martinvalley@comcast.net> wrote in message
>> news:2f83l0hvjgqhr0a645400cdg6oi2u6k5ai@4ax.com...[color=darkred]
>>> This is probably more of an HTML question than PHP. Perhaps someone
>>> here can answer or point me to a proper newsgroup.
>>>
>>> How can I force the browser to reload an image from the server?
>>>
>>> I have a page where the user can set some parameters and click a
>>> <submit> button. A PHP script then generates a .png graphic and saves
>>> it to disc. An html statement (<p><img src="gMyGraphic.png"></p>) then
>>> sends the graphic out to the browser.[/color]
>>
>> The easiest way is to stick a random number into the URL:
>>
>> <img src="gMyGraphic.png?<? echo rand(1,3000); ?>">
>>
>> Consider outputting the image data directly from the PHP script to the
>> browser.[/color]
>
>time() instead of rand() should suffice and is even more easier... and you
>won't get the old image by random... (you have a 1 in 3000 chance to see
>the old image again...)[/color]
Good suggestion - thanks.
I added the rand(1,100) and it worked but, like you say, I was getting
an old image every once in a while. I changed it to rand() which
eliminated that but the potential is still there. With time(), it's
guaranteed to always be a different number.
[color=blue]
>
>Maybe a bit more complex, but even better than rand() or time() would be
><img src="myimage.png?<?php echo filemtime('myimage.png') ?>">
>since it doesn't *completely* turn off caching.[/color] |