Stop data inserting into a database twice

后端 未结 16 1373
再見小時候
再見小時候 2020-12-01 00:33

I was wondering what methods/preventions other programmers use to stop data being entered twice into a MySQL database when a user refreshes on the same page as a form? Obvio

16条回答
  •  长情又很酷
    2020-12-01 00:55

    POE (Post Once Exactly) is an HTTP pattern aimed at warning the client to block double submits using a proprietary header ...

    GET /posts/new HTTP/1.1
    POE: 1
    ...
    

    ... but is still in specification.

    http://www.mnot.net/drafts/draft-nottingham-http-poe-00.txt

    I think the above nonce is a good solution. Though storing the nonce as a discrete session variable will introduce some errors if the client is attempting to perform simultaneous posts from multiple tabs. Maybe better to ...

    $_SESSION['nonces'][] = $nonce;
    

    ... and ...

    if (in_array($_POST['nonce'], $_SESSION['nonces'])) {
    

    ... to allow for multiple nonces (nonci? noncei?).

提交回复
热议问题