Jessica Posted August 22, 2007 Share Posted August 22, 2007 I am having a problem where I suspect images are being cached, despite using the following headers from the PHP.net manual: header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past Here is the page, and the steps to create the problem: http://www.cubedpop.com/create/tags/ It should load a rectangle "tag" with the current timestamp in it. The tag object is stored to the session. Click on Tag Shape and a php page is loaded via Ajax (JS from to Mootools.net) with a bunch of shapes. Click any one of them but the rectangle. This loads a new page via ajax. This page changes the shape of the tag, and saves it to the session. Then it "draws" the image: print '<img src="http://cubedpop.com/create/process/draw/tag/" />'; IF I change this to below, it works perfectly. However, I hate the ugly URL it creates. There has got to be a way to stop the caching! Why do my cache headers not work? print '<img src="http://cubedpop.com/create/process/draw/tag/?t='.time().'" />'; If it is NOT the headers/caching issue, here is more info: Note: I use an htaccess file to redirect all pages to a base file which includes the library files and the session_start(), site-wide constants, etc. Here is the code of the draw tag file: <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past $drawTag = $_SESSION['drawTag']; header("Content-type: image/png"); // Create the image $im = imagecreatefrompng(TAG_SHAPE_IMG_URL.$drawTag->shape->image); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagettftext($im, 14, 0, 50, 50, $black, FONT_PATH.'tahoma.ttf', time()); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> As you can see, the image is not updated when you change the shape. However, if you make the change, then view just the image in your browser: http://www.cubedpop.com/create/process/draw/tag/ The timestamp will update, and the new shape appears. Because the change is made I can tell the session was saved properly. So, this leads me to think the image is caching. Also, if I print_r($_SESSION) on the page which changes the shape and then displays the image, the session contains the correct new shape in it, yet the image is wrong, and the timestamp is old. Help...! Quote Link to comment https://forums.phpfreaks.com/topic/66261-image-still-caching-or-possibly-problem-with-ajax-session/ Share on other sites More sharing options...
Hypnos Posted August 22, 2007 Share Posted August 22, 2007 Cache issues are usually problems with specific browsers *cough*IE*cough*. What browser are you testing with? Try using session_cache_limiter('nocache'); instead of those header lines. The site is loading very slow. Some of the things are timing out for me. Quote Link to comment https://forums.phpfreaks.com/topic/66261-image-still-caching-or-possibly-problem-with-ajax-session/#findComment-331418 Share on other sites More sharing options...
Jessica Posted August 22, 2007 Author Share Posted August 22, 2007 I was testing in Fx. Doesn't the session_cache_limiter affect the session? Not things like images? I was trying to upload a very large file just now, that might be why it was slow. I am heading out so if it is still slow later I'd love to know - I'm using MT so I will yell at them if it's slow! Quote Link to comment https://forums.phpfreaks.com/topic/66261-image-still-caching-or-possibly-problem-with-ajax-session/#findComment-331420 Share on other sites More sharing options...
Barand Posted August 22, 2007 Share Posted August 22, 2007 I had a similar issue recently. Calling an xmlhttp request on page load in IE after a db update always displayed the page without the latest updates. Firefox was fine. The cure - it was the request that was being cached by IE (URL was same so it doesn't bother re-sending, just displays the last results) so adding current timestamp to the URL (making it different every time) resolved the issue. Quote Link to comment https://forums.phpfreaks.com/topic/66261-image-still-caching-or-possibly-problem-with-ajax-session/#findComment-331427 Share on other sites More sharing options...
Jessica Posted August 23, 2007 Author Share Posted August 23, 2007 Hey Barand, I know about that as a fix and I said that in my post I don't like doing that as it makes the URL messy looking. Couldn't there be another way to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/66261-image-still-caching-or-possibly-problem-with-ajax-session/#findComment-331520 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.