.::: 一路问情 :::.
  • 注册
  • 登录
  • 会员
  • FTP资源中心
  • 七海争霸
  • 社区设施
  • 帮助
.::: 一路问情 :::. » 『建站技术』 » 避免表单的重复提交的方法
‹‹ 上一主题 | 下一主题 ››
发新话题
  • 发新话题
  • 发布投票
  • 发布商品
  • 发布悬赏
  • 发布活动
  • 发布辩论
  • 发布视频
打印

[技术] 避免表单的重复提交的方法

ivanisme
看贴不回的后果

初级会员

帖子
83 
威望
30 点 
金钱
201 元 
好评
0 点 
  • 个人空间
  • 发短消息
  • 加为好友
  • 当前离线
1楼 大 中 小 发表于 2008-2-26 09:28  只看该作者

避免表单的重复提交的方法

你是否遇到过“重复提交”的问题?要解决这个问题其实并不难。这里有一个简单的方法避免同一表单的重复提交。

首先,我们可以定义一个session变量用来保存一个表单的提交序列号。这里我定义为“$userLastAction”。

然后在表单里加入一个hidden变量,把值设为$userLastAction+1:

<input type=Hidden name=lastAction value=<? =$userLastAction+1 ?>>

最后,在处理提交之前判断表单是否已被提交过:

if($lastAction>$userLastAction and inputIsValid(...)){
$userLastAction++; // 序列号加1
// 处理表单数据
}

Avoid multiple form submissions
Submitted By: Douglas E. Cook
Date: 07/26/00 19:46
Does your database suffer from "duplicate post" syndrome? The cure isn't too difficult. Here is a simple way to prevent users from submitting the same form multiple times.

First, declare a session variable to store a serial number for each form. I call mine "$userLastAction." Then, in every form where duplicate submission is a problem, include a hidden field, and set the value to $userLastAction+1:

<INPUT TYPE=HIDDEN NAME=lastAction VALUE=<?= $userLastAction+1 ?>>

Finally, verify that the form has not been previously submitted before acting on the submission:

if($lastAction>$userLastAction and inputIsValid(...)){
$userLastAction++; // Increment serial number
// Act on form here
}

这只是一个小技巧,用来避免一个表单的重复提交。这样多少可以防止一些灌水的现象,另外有时候由于网络状况等原因用户不知道提交是否成功,也会再次提交同一份表单。

这个技巧的主要原理是不允许用户回退后再次提交,也就是说回退后修改再提交也是不允许的,而且也不能避免Ctrl-C/Ctrl-V的灌水办法。究竟有没有用,还是看各位站长的喜好了。



QQ
UID
73836 
精华
0 
积分
30 
钻石
0 克拉 
宣传
0 点 
来路
搜索引擎 
阅读权限
10 
来自
上海 
在线时间
0 小时 
注册时间
2008-2-25 
最后登录
2008-2-26 

查看详细资料

TOP

beauty511

初级会员

帖子
8 
威望
10 点 
金钱
47 元 
好评
0 点 
  • 个人空间
  • 发短消息
  • 加为好友
  • 当前离线
2楼 大 中 小 发表于 2008-3-19 23:59  只看该作者

beauty511

wedding dress
bride
abito
vestido
abito
flower gril
party dress
evening dress
http://www.beauty511.com
traje de novia
Brautkleider
<a href="http://www.beauty511.com/shop2/index.php" >wedding dress</a>
<a href="http://www.beauty511.com/shop2/catalog_31.html" >bride</a>
<a href="http://www.beauty511.com/" >abito</a>
<a href="http://www.beauty511.com/Girls.php" >flower gril</a>
<a href="http://www.beauty511.com/Voyage.php" >party dress</a>
<a href="http://www.beauty511.com/" >evening dress</a>
<a href="http://www.beauty511.com/" >vestido</a>
<a href="http://www.beauty511.com/" >traje de novia</a>
<a href="http://www.beauty511.com/" >Brautkleider</a>
http://www.beauty511.com/



QQ
UID
85068 
精华
0 
积分
10 
钻石
0 克拉 
宣传
0 点 
来路
朋友介绍 
阅读权限
10 
性别
女 
来自
suzhou 
在线时间
0 小时 
注册时间
2008-3-19 
最后登录
2008-3-19 

查看详细资料

TOP

‹‹ 上一主题 | 下一主题 ››
发新话题
 

 

当前时区 GMT+8, 现在时间是 2008-7-6 04:14 蜀ICP备08000616号

清除 Cookies - 联系我们 - Ask Love - Archiver - WAP - TOP

Powered by Discuz! 6.0.0 []

Processed in 0.015123 second(s), 5 queries, Gzip enabled.

  • 控制面板首页
  • 编辑个人资料
  • 积分交易
  • 积分记录
  • 公众用户组
  • 个人空间管理
  • 资源中心
  • 名人堂
  • 社区银行
  • 醒目高亮
  • 勋章中心
  • 空间互踩
  • 便民查询
  • 邮箱图标
一路问情友情提示你:单帖回复不可以三帖连续哦!
一路问情友情提示你:单帖回复不可以三帖连续哦!