Page 1 of 1

How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 12:10 am
by naveed82
hello all,

I m uploading an image in php page and path of image is saving in db. but after 2nd or 3rd itteration there previous image is displayed. When i refresh that page then new uploaded image display.

please tell me way of clearing cache of browser on runtime of php application or any other way of solving this problem

thanks in advance . . .

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 1:04 am
by jmut
are you serving the image directly or from php script?

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 1:31 am
by naveed82
Yes, we are using PHP script from getting path of image (which is on locally on system) from DB and then display on php page in application ...

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 2:09 am
by jmut
header("Cache-Control: no-cache");
you can try something like this as one of the headers when displaying the image.

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 2:13 am
by naveed82
i have checked these snappits of code for this problem ...


// 1st snappit
header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past



//2nd snappit
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Data passata
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// sempre modificato
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

but these snappits are not working as my requirement.

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 2:22 am
by jmut
some tough browser you have there :)

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 2:55 am
by naveed82
:lol: browser is mozilla but i think there is problem with image size because when i upload image with size of less than 100 kb then it shows without refreshing page but when i upload image with size of greater than 100 then i have to refresh page manually for display that new uploaded image ...

Re: How can I clear cache of browser on runtime

Posted: Thu Feb 28, 2008 3:06 am
by naveed82
thanks for you coporation ..


i have solved this problem using the statement given below:

<img src="someimage.png?x=<?=uniqid((double)microtime()*1000000,1)?>">


thanks again