Web Analytics Made Easy -
StatCounter Serioud Cache Problem ? - CodingForum


No announcement yet.

Serioud Cache Problem ?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Serioud Cache Problem ?

    I have a image upload script, which replaces one picture by another, there is always the same amount of images, now everything works fine but

    When I upload a picture (and the page refresges), it shows the last picture (which doesn't exists anymore) and not the current one, by checking the HDD I know it is uploading/updating it, but it is not showing properly on the PHP.

    I have tried with:

    PHP Code:
    header"Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
    header"Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT" );
    header"Cache-Control: no-cache, must-revalidate, pre-check=0, post-check=0'" );
    header"Pragma: no-cache" ); 

    PHP Code:
    if ($_GET['refresh'])
    '<body onload=`location.replace("' str_replace('&refresh=1'''$_SERVER['REQUEST_URI']) . '");`>';

    PHP Code:
    echo '<a href="' $_SERVER['PHP_SELF'] . ?'blah-blah=blah&refresh=1">Continue</a>'

    PHP Code:
    echo '<form action="' $_SERVER['PHP_SELF'] . '" method="post" enctype="multipart/form-data" name="' rand() . '">'
    PHP Code:
    echo '<img src="' $pic_loc[$i] . '" border="0" name="' rand(). '" id="' rand(). '">'

    Like you can see, I use rand() to create various names for all variables, to try the browser from caching it in.
    Also, once someone uploads a picture, a blank page with a Continue link comes up, he clicks on that and is redirected to the page where is shows the picture which is then refreshed by javascript.

    But nothing of those methods work, what I am doing wrong?

    thanks in advance
    Last edited by MeGa; Feb 25, 2004, 01:17 AM.
    MeGa MaX
    Be the Best, but don't Believe it.

  • #2
    try using meta tags in the <head> section of your HTML to fix:

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="express" content="-1">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="imagetoolbar" content="no">
    Failing that, open the "internet options"control panel and click the "settings" button in the "temporary internet files" section. make sure the first option (every visit) is selected.
    My body's a temple... and like those ancient Greek ones it's a ruin


    • #3
      Another way is to use a querystring on the end of the image url, like:
      PHP Code:
      echo '<img src="' $pic_loc[$i] . '?'.time().'" border="0" name="' rand(). '" id="' rand(). '">'


      • #4
        I think that adding the querystring is the only real option.
        Every sollution that requires specific browsersettings is doomed to fail for some of your clients, so unless you'll be the only visitor ... Not all browsers will process the meta-tags correctly so that isn't realy a bulletproof way either.
        I also think that the page could be cached somewhere else then on the clients machine so i think that the querystring might be your best bet.
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


        • #5
          WOW, that is really a nice trick Nightfire, Thanks a lot for your help!!
          MeGa MaX
          Be the Best, but don't Believe it.