How can I prevent database being written to again when the browser does a reload/back?

后端 未结 7 1566
天涯浪人
天涯浪人 2021-01-06 01:06

I\'m putting together a small web app that writes to a database (Perl CGI & MySQL). The CGI script takes some info from a form and writes it to a database. I notice, h

7条回答
  •  旧巷少年郎
    2021-01-06 01:35

    I'd not rely on POST warnings from the browser. Users just click OK to make messages go away.

    Anytime you'll have a request that needs to be one time only e.g 'make a payment', send a unique token down, that gets submitted back with the request. Throw the token out after it comes back, and so you can now tell when something is a valid submission (anything with a token that isn't 'active'). Expire active tokens after X amount of time, e.g. when a user session ends.

    (alternately track the tokens that have come back, and if you have received it before then it is invalid.)

提交回复
热议问题