user1929236
user1929236

Reputation: 125

how to stop image from caching in php

I am having this problem of image i.e image is not reloading on page refresh as it is an .gif image and i have to show the transition on each page refresh.

<?php if ($page == "index") { ?>
        <img src="images/Karpel_logo.gif" alt="" />
        <?php } else { ?>
        <a href="http://www.karpellaw.com/test"><img id="graph" src="images/Karpel_logo.gif?dummy=371662" alt="" /></a>
        <?php } ?>

 live link :    www.karpellaw.com/test

Upvotes: 1

Views: 194

Answers (3)

Prasanth Bendra
Prasanth Bendra

Reputation: 32730

Every time when you refresh the page, change the src of the image tag :

<img src="images/Karpel_logo.gif?<?php echo time();?>" alt="" />

OR you can append any random number and the end of the image src.

Upvotes: 0

Put a ?a=time()

<?php if ($page == "index") { 
          echo '<img src="images/Karpel_logo.gif?a='.time().'" alt="" />';
         } else {
        echo '<a href="http://www.karpellaw.com/test"><img id="graph" src="images/Karpel_logo.gif?dummy=371662&a='.time().'" alt="" /></a>'
     } 
?>

Upvotes: 0

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

use random integer for every page refresh. It will forcefully load new image rather then cached image.

<img src="images/Karpel_logo.gif?<?php echo rand(); ?>" alt="" />
<?php } else { ?>
<a href="http://www.karpellaw.com/test"><img id="graph" src="images/Karpel_logo.gif?dummy=<?php echo rand(); ?>" alt="" /></a>
<?php } ?>

Upvotes: 2

Related Questions