--------------------------------------------------------------------------------------------------- 1. 使用JS让按钮在点击一次后禁用(disable)。= 防止多次点击发生,实现方式较简单。 缺点:若客户端禁止JavaScript脚本,则失效。 2. 在提交成功后
---------------------------------------------------------------------------------------------------
1. 使用JS让按钮在点击一次后禁用(disable)。=> 防止多次点击发生,实现方式较简单。
缺点:若客户端禁止JavaScript脚本,则失效。
2. 在提交成功后执行页面重定向(redirect)。=> 转到提交成功信息页面。
特点:避免F5重复提交,消除浏览器前进和后退按导致的同样问题。
3. 表单隐藏域中存放session(表单被请求时生成的标记)。=> 接收表单数据后,检查此标志值是否存在,先进行删除,然后处理数据; 若不存在,说明已提交过,忽略本次提交。
<span>/*</span><span> |--------------------------------- |原理 & 代码示例 |@黑眼诗人 <www.farwish.com> |--------------------------------- </www.farwish.com></span><span>*/</span> <span>//</span><span>服务端生成随机数存入session, 分配至表单页</span> <span>$data</span>['sess_id'] = <span>$_SESSION</span>['sid'] = <span>mt_rand</span>(1000, 9999<span>); </span><span>$this</span>->load->view('form', <span>$data</span><span>); </span><span>//</span><span>表单页隐藏域存放此session值</span> <input type="hidden" name="sid" value="<?=<span>$sess_id</span>; ?>"> <span>//</span><span>处理</span> <span>if</span>(<span>$_POST</span>['sid'] != '' && $_POST['sid'] == $_SESSION['sid']<span>) { </span><span>unset</span>(<span>$_SESSION</span>['sid'<span>]); </span><span>echo</span> '处理数据'<span>; } </span><span>else</span><span> { </span><span>echo</span> '已提交过表单'<span>; }</span>
4. 数据库唯一索引约束(最有效的防止重复数据的方法)。
Link: http://www.cnblogs.com/farwish/p/3911588.html
@黑眼诗人

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft