How can I clear cache of browser on runtime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naveed82
Forum Newbie
Posts: 7
Joined: Thu Feb 28, 2008 12:01 am
Location: Islamabad, Pakistan
Contact:

How can I clear cache of browser on runtime

Post 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 . . .
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: How can I clear cache of browser on runtime

Post by jmut »

are you serving the image directly or from php script?
naveed82
Forum Newbie
Posts: 7
Joined: Thu Feb 28, 2008 12:01 am
Location: Islamabad, Pakistan
Contact:

Re: How can I clear cache of browser on runtime

Post 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 ...
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: How can I clear cache of browser on runtime

Post by jmut »

header("Cache-Control: no-cache");
you can try something like this as one of the headers when displaying the image.
naveed82
Forum Newbie
Posts: 7
Joined: Thu Feb 28, 2008 12:01 am
Location: Islamabad, Pakistan
Contact:

Re: How can I clear cache of browser on runtime

Post 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.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: How can I clear cache of browser on runtime

Post by jmut »

some tough browser you have there :)
naveed82
Forum Newbie
Posts: 7
Joined: Thu Feb 28, 2008 12:01 am
Location: Islamabad, Pakistan
Contact:

Re: How can I clear cache of browser on runtime

Post 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 ...
naveed82
Forum Newbie
Posts: 7
Joined: Thu Feb 28, 2008 12:01 am
Location: Islamabad, Pakistan
Contact:

Re: How can I clear cache of browser on runtime

Post 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
Post Reply