国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

如何避免表單的重復提交

2019-09-08 23:11:05
字體:
來源:轉載
供稿:網友
你是否遇到過“重復提交”的問題?要解決這個問題其實并不難。這里有一個簡單的方法避免同一表單的重復提交。
首先,我們可以定義一個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
}

譯自:phpbuilder
這只是一個小技巧,用來避免一個表單的重復提交。這樣多少可以防止一些灌水的現象,另外有時候由于網絡狀況等原因用戶不知道提交是否成功,也會再次提交同一份表單。
這個技巧的主要原理是不允許用戶回退后再次提交,也就是說回退后修改再提交也是不允許的,而且也不能避免Ctrl-C/Ctrl-V的灌水辦法。究竟有沒有用,還是看各位站長的喜好了。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广河县| 舞钢市| 新闻| 拜城县| 武功县| 荆州市| 沁源县| 芒康县| 临高县| 桃江县| 祥云县| 无极县| 南京市| 玉龙| 天镇县| 左云县| 陇川县| 周口市| 卫辉市| 金塔县| 含山县| 龙胜| 云梦县| 闻喜县| 建昌县| 辽阳市| 右玉县| 大庆市| 高唐县| 慈利县| 微山县| 临澧县| 铜梁县| 句容市| 石屏县| 禹州市| 林西县| 舒城县| 永吉县| 原平市| 夏河县|