Caching woes

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
froth
Forum Commoner
Posts: 31
Joined: Sat Jan 22, 2005 9:26 pm

Caching woes

Post by froth »

I'm having some severe caching problems... I've made an elaborate signature-switcher for forums that allows users to select your sig on-the-fly with a cool little selection interface. What it does is when the user selects a signature, it rewrites redir.php (which is where the signature's img tag points to) to say:

Code: Select all

header(&quote;Location: SIGLOCATION&quote;)
With SIGLOCATION of course being the url to the sig the user selected. The problem is that the browser caches the image at SIGLOCATION and assumes php is just some image extension (and so has no problem caching) so to actually see the change, the user has to clear his/her temporary internet files or switch browsers or just shift-refresh. To stop the caching, I'm adding anticache headers to redir.php... but to no avail:

Code: Select all

header(&quote;Age: 2147483648&quote;);
header(&quote;Expires: Mon, 31 Dec 2001 23:59:59 GMT&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Cache-control: no-store, max-age=1&quote;);
The browser still caches the page! When I shift-refresh the forum page with the img tag (the signature) it works fine. But if I just refresh, it gets the image from cache instead of from redir.php. Is there anything I'm missing that I can do from the server-side (obviously my options are limited in the actual html of the forum page), like maybe in htaccess?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Been using these header, right out of the manual, to prevent caching. They seem to work.

Code: Select all

// No Page Caching.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Have you checked your browser settings? I forgot I changed my settings once and nearly drive myself nuts with a caching bug.
froth
Forum Commoner
Posts: 31
Joined: Sat Jan 22, 2005 9:26 pm

Post by froth »

Hm, it didn't work. :(
No I haven't messed around with any browser cache settings.
froth
Forum Commoner
Posts: 31
Joined: Sat Jan 22, 2005 9:26 pm

Post by froth »

Hm, that's interesting. IE doesn't cache it at all. But Firefox does.

Here's a link to one of my posts: Here
Click my signature to change the sig, then go back and refresh to see if it worked. It works in IE. It doesn't work in Firefox unless you Shift-Refresh the forum page. Also try viewing the location of the signature image and then directing your whole browser window to it... FF doesn't cache that. Thanks!
froth
Forum Commoner
Posts: 31
Joined: Sat Jan 22, 2005 9:26 pm

Post by froth »

Just bumping.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Might try adding a unique dangle through a redirect:

http://frother6.webpal.info/rotate/froth

redirects to

http://frother6.webpal.info/rotate/froth?random=XXXXXXX

Just an idea ...
froth
Forum Commoner
Posts: 31
Joined: Sat Jan 22, 2005 9:26 pm

Post by froth »

But where would I put it? There would be no way to add a random dangle within the Signature field in my profile...
Post Reply