HTML / PHP cache solution -anyone clever enough to solve this?

Discussion in 'Programming' started by SteelRat, May 16, 2008.

  1. #1
    Problem:

    A picture is updated on the server - the picture itself is changed but not the picture name. But the browsers (diferent locations, different computers, different OS, trying both IE / Netscape) - display the old image until refresh clicked or F5 key is pressed.

    Already tried
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    Header("Cache-Control: max-age=1, must-revalidate, no-store");
    $expire = "Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT";
    Header($expire);
    :confused:

    Is there anyone clever enough to solve this one?? ;)
     
    SteelRat, May 16, 2008 IP
  2. Perow

    Perow Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Could you post the complete script? You could use a random number to prevent loading from cache.
     
    Perow, May 16, 2008 IP
  3. King Goilio

    King Goilio Member

    Messages:
    200
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    33
    #3
    try adding this:
      Header('Cache-Control: no-cache');
    Header('Pragma: no-cache');
    PHP:
     
    King Goilio, May 16, 2008 IP
  4. SteelRat

    SteelRat Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    already have the whole set of those...

    session_cache_expire( 0 );
    session_cache_limiter( "nocache" );
    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");

    doesn't seem to help
     
    SteelRat, May 17, 2008 IP
  5. SteelRat

    SteelRat Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    there is no script really... I want to keep the main page w/o any SQL queries... every 15 mintues I'll run a script that copies a picture from from top list and latest pictures list to another picture, ie "femalelast.jpg" etc

    there is static link on the main page, for example:

    <td width=125 align="center" valign="middle">
    <?php
    echo "<a href='lastpic.php?mode=female'>";
    ?>
    <img src="/sp/femalelast.jpg" hspace=2 vspace=2><BR>
    <b>Women</b></a><BR>
    </td>

    (don't ask why I have got the PHP in the middle... probably copy-pasted something when I wrote this and then made some changes or whatever. not relevant I guess in any case)

    the script that copies the picture (in a special PHP page) is simple

    while ($l = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $fromcopy = "/th/t" . $l['pic'];
    unlink ("/sp/femalelast.jpg");
    copy ($fromcopy,"/sp/femalelast.jpg");
    }

    This worked for 3 months, ad stopped working a week ago....

    (the unlink was added yesterday, no help though)
     
    SteelRat, May 17, 2008 IP
  6. SteelRat

    SteelRat Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok.. now i see what you mean... so now I am using

    echo "<img src='/sp/femalelast.jpg?" . time() . "' hspace=2 vspace=2><BR>";

    this will force a reload - seems that I will lose any cache ability.... but at least the picture is up to date... ;) ... umm guess you can't have both...

    now I can get rid of the header and HTTP-EQUIV stuff as well
     
    SteelRat, May 17, 2008 IP
  7. Perow

    Perow Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Well, unless you'd be holding a flag somewhere that indicates whether the image has been changed since it was last loaded to the user's browser, you'd have to choose between caching or reloading. In this case, reloading seems to be the best option.
     
    Perow, May 17, 2008 IP