faqts : Computers : Internet : Web : HTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 24 people (88%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How can you force an image generated by a PHP program to be refreshed, rather than obtained from cache, in Netscape, <IMG SRC="xxxx.php?var=sss">?

Jun 6th, 2002 14:42
Colin Snover, Matthias Zirngibl, Andrew Peckover,


Simply call the PHP-script with an additionally dummy-paramter which is 
generated from JavaScript or PHP:
Instead of 
<IMG SRC="xxxx.php?var=sss">
use
<script><!--
a = Math.random();
document.writeln("<IMG SRC=\"xxxx.php?var=sss&dummy=" + a + "\">");
--></script>
If you use PHP, you can do it this way:
<?
$a = rand();
print "<IMG SRC=\"xxxx.php?var=sss&dummy=$a\">";
?>
The Browser thinks the image is alway another one, cause the url is an 
other...
---
A better way is to write header "Pragma" with content "No-Cache".