Force Update on Cached Images

Discussion in 'PHP' started by heyman12, Apr 6, 2009.

  1. #1
    I have been using PHP scripts that dynamically create images, but the problem is, these images are cached. Is there a way I can force the browser to update the cache on each view?
     
    heyman12, Apr 6, 2009 IP
  2. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The header() function - see php.net
     
    Pos1tron, Apr 9, 2009 IP
  3. risoknop

    risoknop Peon

    Messages:
    914
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    An easier way... change the URL to the image based on a randomly generated string, example:

    
    http://www.example.com/images/image.png?randomstr=787dsa1
    
    Code (markup):
    That will make the browser reload the image every time (except the randomly generated string will be the same two times in a row which is almost impossible).

    Richard
     
    risoknop, Apr 10, 2009 IP
  4. amine

    amine Active Member

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    93
    #4
    you must edit http header

    header("Cache-Control: no-cache, must-revalidate");
     
    amine, Apr 11, 2009 IP