简体   繁体   English

单击提交按钮后按f5

[英]hitting f5 after clicking the submit button

I have a PHP application where users can apply for a bonus. 我有一个PHP应用程序,用户可以申请奖金。 But there is a confirmation page before the bonus redemption code runs. 但是在奖励兑换代码运行之前有一个确认页面。 The issue is that in IE , if you hit f5 right after you click the continue button, the confirmation page refreshes while the bonus redemption code had already been triggered by the continue button and actually goes through. 问题是在IE中 ,如果您在单击“继续”按钮后立即点击f5 ,则确认页面会刷新,而奖励兑换代码已由“继续”按钮触发并实际通过。 But because the user still sees the confirmation page, they would hit the continue button again and now they get an error cause they are already registered. 但由于用户仍然看到确认页面,他们会再次点击“继续”按钮,现在他们会收到错误,因为他们已经注册了。

Is there a way i can disable the f5 button using javascript ? 有没有办法可以使用javascript禁用f5按钮? Is this the best way to go about this? 这是解决这个问题的最好方法吗? I have tried many scripts i found online to do this, but none of them achieves it. 我尝试过很多我在网上找到的脚本,但是没有一个能实现它。 Is there a better way I can go about this? 有没有更好的方法可以解决这个问题? Perhaps from the application side? 也许来自应用方面?

Edit: If the outcome of claiming a bonus is databased, you can load existing claims on your confirmation screen and test that one already exists. 编辑:如果声明奖金的结果是数据库,您可以在确认屏幕上加载现有的声明并测试已存在的声明。


Edit: the other neat trick you can do is serailize/json_encode the $_POST and produce a hash from this, store it in the database or user session, and test against it. 编辑:你可以做的另一个巧妙的技巧是serailize / json_encode $ _POST并从中产生一个哈希,将其存储在数据库或用户会话中,并对其进行测试。


I would generate and database a single use token (hash) for the form as a hidden field, if post data is re-sumbited, the token would have already been consumed, and you can invalidate the post request. 我将生成并将数据库的单个使用令牌(哈希)作为隐藏字段进行数据库生成,如果重新汇总后期数据,则该令牌已经被使用,并且您可以使该请求无效。

There are couple of methods to solve your issue: 有几种方法可以解决您的问题:

Checkout here: http://bjw.co.nz/developer/general/75-how-to-prevent-form-resubmission 在这里结账: http//bjw.co.nz/developer/general/75-how-to-prevent-form-resubmission

I have been using second method (Using sessions) and it's really working well. 我一直在使用第二种方法(使用会话),它确实运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM