Back to Home: PHP FormMail Generator I Need Help : Ask Question Without Registration

Make email form not be cached by browsers and proxy servers
  • admin September 2011
    Question:

    I would like to make sure the web browser does not store the form in
    cache. What shall I add to the code to make sure the browser gets code
    every time

    Answer:

    In form.lib.php, you can add the following highlighted code to force the form not be cached by browser or proxy :

    function phpfmg_init(){

      error_reporting( E_ERROR );
      ini_set('magic_quotes_runtime', 0);
      ini_set( 'max_execution_time', 0 );
      ini_set( 'max_input_time', 36000 );
      session_start();
      phpfmg_check_referers();

      if ( get_magic_quotes_gpc() && isset($_POST) ) {
          phpfmg_stripslashes( $_POST );
      };
     
      phpfmg_no_cache();
     
    }

    function phpfmg_no_cache(){
        $expired = gmdate( "D, d M Y H:i:s", time()-1800 ) . " GMT"; // 1800 seconds ago
        header("Expires: " . $expired );
        header("Last-Modified: " .$expired );
        header("Cache-Control: post-check=0, pre-check=0, max-age=0, no-store, no-cache, must-revalidate");
        header("Pragma: no-cache");
    }

    Please remember to upload the updated file back to your website.

    You might also want to read below information. I copied it from http://php.net/manual/en/function.header.php :

    You may find that your pages aren't cached even if you don't
    output all of the headers above. There are a number of options
    that users may be able to set for their browser that change its
    default caching behavior. By sending the headers above, you should
    override any settings that may otherwise cause the output of your
    script to be cached.



    Additionally, session_cache_limiter() and
    the session.cache_limiter configuration
    setting can be used to automatically generate the correct
    caching-related headers when sessions are being used.