How to force a refresh in current page?

Appreciate it if someone can show me the code.

Reason: I have a page that allows user to change an image file. The image file is updated in the file directory. However, the 'old' image still shows in the current browser. The image will be updated only when I do a 'refresh' on the page. (But I can't possibly tell the user to 'refresh' the page, there must be a way to do it by codes, isn't it?)

Thanks.

    Not in PHP. PHP doesn't do anything on the browser.

    But try searching the forums. Or Google. You're not the first person to ask. You probably won't be the last, either.

      But what if I only need to refresh once? It seems I have to key in a value for it to refresh every x seconds. But I need only to refresh once.
      Thanks anyway for your kind reply.

        You could enclose the meta tag in some php which checks if some variable is set, and if it is, it doesn't echo the meta tag. For example:

        <?php
        if (!isset($_GET['dorefresh'])) {
            echo "meta tag goes here";
            // in the meta tag, the link contains the text ?dorefresh=1
        }
        ?>
        

        That way, the first time you load the page, the meta tag will be put into the page, but the second time it won't, because the $_GET['dorefresh'] variable will be set, because the meta tag contains the ?dorefresh=1 text.

        Of course, if you've got other variables being initialized in the address, then replace that with &dorefresh=1.

          [Resolved]Thanks a million! It works!

            Dear bbreslauer ,

            I tried your solution. It works when the value of the variables is fixed. But because I used $HTTP_GET_VARS to get the values of the variable. As a result, when the page refreshes, the value is gone. Snippet of my code is as follows:

            if (!isset($_GET['dorefresh'])) {
            $var= $HTTP_GET_VARS['var'];

            echo '<meta http-equiv="refresh" content="2;url=show_cat.php?catid=$var&dorefresh=1">';

            }

            The resulting page looks like this:

            http://localhost/test/show_cat.php?catid=$var&dorefresh=1
            But I need this to work:
            http://localhost/test/show_cat.php?catid=1&dorefresh=1

            No matter how hard I tried, the value of the variable does not get registered.
            Is there any solution to this problem? Thanks greatly!

              Yeah, that's a common problem with the " and ' quotes. In order to make sure the variable will be echo'ed, and not the name of the variable, use this code instead:

               echo '<meta http-equiv="refresh" content="2;url=show_cat.php?catid='. $var .'&dorefresh=1">'; 
              

              By doing this, you end the string after catid= and then concatenate the $var variable, and then concatenate the &dorefresh onto that, using the concatenate operator (the period).

                :p Gee, you are a genius. Can't thank you enough!

                  Write a Reply...