Reputation: 2011
I've spent weeks working on double-submit protection on my forms. Straightup, the session method of storing tokens doesn't work.
Sessions work fine for a refresh of the page or someone going back through their history... but the classic double submit by clicking the button numerous times cannot be prevented using sessions.
I'm thinking the script cannot check/write/delete sessions fast enough to catch the error when multiple clicks are being processed within milliseconds of each other.
Is there another server side method to preventing this problem?
Upvotes: 2
Views: 1202
Reputation: 70490
It seems you need an independant token store capable of avoiding race conditions. To get this to work several solutions are available, one of the easier to implement would be:
microtime()
, possibly even a process-id, or hash, as long as it's very much assured to be unique in similar processes started within moment from each other.UPDATE tokens SET claimid = <id> WHERE tokencode=tokencode AND claimid IS NULL
Upvotes: 3