Reload/refresh page in browser without re-submitting form?

前端 未结 3 1316
无人共我
无人共我 2020-12-17 04:57

I have a form on a php page that is submitted to the same page. I noticed that if I reload/refresh the page the form gets re-submitted. How do I code to avoid this in the mo

3条回答
  •  旧时难觅i
    2020-12-17 05:21

    This assume a lot of things, but maybe is what you are looking for:

    if ($_POST)
    {
        $success = false;
    
        /*
         * if all goes OK managing POST data make $success = true;
         * 
         */
    
        if ($success)
        {
            // this will redirects to your original
            // form's page but using GET method
            // so re-submitting will be no possible
            header("location: {$_SERVER['PHP_SELF']}");
            exit;
        }
    }
    

提交回复
热议问题