How to prevent refresh page error while submitting

2019-01-26 20:03发布

When registration form submits using POST method and when you refresh the same page then it will prompt for resubmit or resend information. How we can prevent this?

4条回答
Deceive 欺骗
2楼-- · 2019-01-26 20:15

You can use ajax. You keep the same php code that you put in another file, and you post the data via ajax.

查看更多
萌系小妹纸
3楼-- · 2019-01-26 20:27

You can use include a one-time random token in the form. The first time that token is submitted (with other data), an action is taken. Future submissions of the same token have no effect (or just show the same confirmation page), and submissions with blank or invalid tokens are rejected.

This also protects against cross-site request forgery.

查看更多
Evening l夕情丶
4楼-- · 2019-01-26 20:32

Try this:

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

I placed it into prevent_resend.php and then included it after the postdata processing was done.

// ... save data from $_POST to DB
include('prevent_resend.php');
// ... do some other stuff
查看更多
做自己的国王
5楼-- · 2019-01-26 20:35
登录 后发表回答