Prevent resubmit form after click “back” button

前端 未结 6 1845
情歌与酒
情歌与酒 2020-12-09 06:57

I have 2 pages :

page1.php :
- has a form with text box and a \"submit\" button. Eg :

6条回答
  •  清歌不尽
    2020-12-09 07:34

    You can prevent the re-submission by implementing the Post-Redirect-Get (PRG Pattern).

    Could be just a one-line if you've got the http_redirect function:

    http_redirect("page2.php");
    

    Instead of your javascript echo.

    If not, that are two lines:

    header("Location: http://example.com/page2.php");
    exit;
    

    Replace example.com with site's your hostname.

    Related: Back button re-submit form data ($_POST); I am confused about PHP Post/Redirect/Get

提交回复
热议问题