How to force page not to be cached in PHP?

后端 未结 6 473
小鲜肉
小鲜肉 2020-12-02 23:59

I have a page, index.php, that shows information based on a mysql db. There are forms on it, and the action for the forms is set to a separate page called process.php. Pro

相关标签:
6条回答
  • 2020-12-03 00:24
    <?php header("Cache-Control: no-cache, must-revalidate");
    
    0 讨论(0)
  • 2020-12-03 00:33

    Make all browsers fall in line:

    header("Location: /webadmin/email/index.php?r=".mt_rand(0, 9999999));
    

    It's not pretty, but it fits the question asked: "How to force..."

    0 讨论(0)
  • 2020-12-03 00:33

    This is the correct order to get it working on all browsers:

    <?php
    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    header("Pragma: no-cache"); // HTTP/1.0
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    ?>
    
    0 讨论(0)
  • 2020-12-03 00:33

    Try fooling the browser with a spurious querystring:

    header("Location: /webadmin/email/index.php?x=1");
    
    0 讨论(0)
  • 2020-12-03 00:38

    I would play safely and try to output all cache killers known to man (and browser). My list currently consists of:

    <?php
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache"); // HTTP/1.0
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?>
    
    0 讨论(0)
  • 2020-12-03 00:40
    <?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?>
    

    do this and it should prevent caching in all browsers

    tested in IE FF and chrome

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