scuff Posted May 15, 2011 Share Posted May 15, 2011 I have a php generated image: (number.txt contains a number 1 or 2) pic.php <?php // Set the content-type header('Content-type: image/bmp'); // Create the image $im = imagecreatetruecolor(80, 80); $count_my_page = ("number.txt"); $hits = file($count_my_page); if ($hits[0] == 1) { $im = imagecreatefrompng("image1.png"); $hits[0] ++; $fp = fopen($count_my_page , "w"); fputs($fp , "$hits[0]"); fclose($fp); }else{ $im = imagecreatefrompng("image2.png"); $hits[0] --; $fp = fopen($count_my_page , "w"); fputs($fp , "$hits[0]"); fclose($fp); } // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 1, 1, 1); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> And I have another page index.html <img src="pic.php"> <img src="pic.php"> Basically, I need one of the images on the index page to be image1 and then the second image to be image2, but it must be contained within the php file because I am unable to edit index.html. Is there anyway to do this? The method I have now where it reads a file to see if it's value is 1 or 2 doesn't seem to compute each time the image is generated. I have tried header("Cache-Control: no-cache"); header("Pragma: no-cache"); in the image code to force it not to cache but to no avail. Can anyone solve this? Quote Link to comment Share on other sites More sharing options...
.josh Posted May 16, 2011 Share Posted May 16, 2011 I think your problem is probably the browser caching the image. Only way to really keep it from doing that is attaching a random number to the request, like <img src="pic.php?n=123"> usually people just do something like this: <img src="pic.php?n=<?php echo time(); ?>"> which just uses the current unix timestamp as the number. ...but you said you can't change index.html. Well..I'm afraid you're out of luck then. Image caching happens in the browser, so you're going to have to change index.html like above or have a meta tag or something specifically telling the browser not to use cached images. Quote Link to comment Share on other sites More sharing options...
scuff Posted May 16, 2011 Author Share Posted May 16, 2011 alright thanks. Quote Link to comment 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.