How to prevent update page error when submitting a POST form?

When the registration form is submitted using the POST method, and when you refresh the same page, it requests a re-submission or re-submission of information. How can we prevent this?

+3
source share
4 answers

Use post-redirect-get . Shortly speaking:

enter image description here

+8
source

You can use ajax. You save the same PHP code that you put in another file and send the data via ajax.

0
source

You can use a one-time random token in the form. The first time this token is sent (with other data), an action is taken. Future representations of the same token do not affect (or simply show the same confirmation page), and deviations with empty or invalid tokens are rejected.

It also protects against cross-site request forgery .

0
source

Try the following:

<?php
if (!empty($_POST)){
?>
    <script type="text/javascript">
        window.location = window.location.href;
    </script>
<?php } ?>

I placed it in a prevent_resend.php file and then included it after postdata processing was complete.

// ... save data from $_POST to DB
include('prevent_resend.php');
// ... do some other stuff
0
source

All Articles