Force page to reload from server instead of load the cached version

前端 未结 6 435
温柔的废话
温柔的废话 2021-01-02 04:20

I have webpage A. The user clicks on a form to submit data, and it takes him to webpage B. When he clicks the back button, I need webpage A to be refreshed from the server,

相关标签:
6条回答
  • 2021-01-02 05:02

    Try with all three:

    <meta http-equiv="cache-control" content="no-cache"> <!-- tells browser not to cache -->
    <meta http-equiv="expires" content="0"> <!-- says that the cache expires 'now' -->
    <meta http-equiv="pragma" content="no-cache"> <!-- says not to use cached stuff, if there is any -->
    
    0 讨论(0)
  • 2021-01-02 05:05

    OK try this instead:

    <?php
        if(!session_id()) {
            @session_start();   
        }
        header('Expires: Sat, 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'); 
    
        if(isset($_SESSION['form_submitted'])) {
            unset($_SESSION['form_submitted']);
            header('Location: ?' . uniqid());
            #header('Refresh: 0');
        }
    ?>
    

    You will need to set $_SESSION['form_submitted'] = true on page 2.

    0 讨论(0)
  • 2021-01-02 05:06
    <?php 
        session_start();
        if(isset($_SESSION['reloadPage'])) {
            unset($_SESSION['reloadPage']);
               //no outputting code above header
            header("Cache-Control: no-cache, must-revalidate");
            header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
            header("Location: http://www.mypage.com/");
        }
    ?>
    
    0 讨论(0)
  • 2021-01-02 05:07

    I know this is old question and already have the answer (that not refreshing from the server). So I would like to share a solution using jQuery.

    $('#back-button').click(function(){
       setTimeout(location.reload(true), 1000);
    });
    

    Explanation:
    As you click the back button, the setTimeout will triggered after 1 second (1000 milliseconds). Then, the page will reload from the server as the parameter inside the reload is true.

    If you put true inside the reload it will reload from the server while if you put false it will reload from the cache. Source w3schools.

    0 讨论(0)
  • 2021-01-02 05:16
    <?php 
      session_start();
      if(isset($_SESSION['reloadPage'])) {
      unset($_SESSION['reloadPage']);
      echo'
      <script>
      window.location.replace("/****/****/*****.php");
      </script>
      ';
    }
    ?>
    
    0 讨论(0)
  • 2021-01-02 05:20

    Your JavaScript should be...

    window.location = "/****/****/*****.php"
    

    I think that should fix your loop.

    0 讨论(0)
提交回复
热议问题