Back button re-submit form data ($_POST)

后端 未结 6 940
鱼传尺愫
鱼传尺愫 2020-11-27 19:23

My problem is that the back button causes the browser to say something like \"Page expired\" when the previous page was created by a form.

Example:

  • pag
相关标签:
6条回答
  • 2020-11-27 20:04

    Send a Location header in the script you POSTed to, pointing to the page that comes after.

    0 讨论(0)
  • 2020-11-27 20:06

    You can use session to do this.

    eg.

    $_SESSION['name'] = $_POST['name'];

    Remember to unset your variables after the process is complete to optimize memory usage.

    0 讨论(0)
  • 2020-11-27 20:08

    Use the Post/Redirect/Get (PRG) Pattern.

    PRG Pattern

    0 讨论(0)
  • 2020-11-27 20:08

    This applies to PHP and IE8.

    Not only must you set cacheing to private, but you must remove the 4 cacheing headers and this can only be done with PHP 5.3. In PHP 5.2 you can only set the 4 headers to blank values if using the Zend Framework's setHeader() method. For some reason is not sufficient on IE8 to set the 4 header values to empty values. Here's the code for PHP 5.3:

        header_remove("Expires");
        header_remove("Cache-Control");
        header_remove("Pragma");
        header_remove("Last-Modified");
    
    0 讨论(0)
  • 2020-11-27 20:11

    Don't use POST for search. Search can safely be done with GET since it won't alter anything.

    0 讨论(0)
  • 2020-11-27 20:25

    If you are submitting a form with search parameters, you are trying to get some data, not modify some.

    So, you should use the HTTP GET method, and not POST : POST should be used when you intend to create/modify data, and GET should be used when you intend to fetch some data.

    Or, if you have some create/modify operation that has to be done :

    • The form first POSTs to a first page
      • That page does some operations (like writing something to a database)
      • And then redirects to another page, using a Location HTTP header.
    • It's that last page, that's queries by the browser using a GET requests, that displays the data fetched from the parameters received in the URL.

    See the Post/Redirect/Get page on wikipedia, about this.

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