1. 二宝博客首页
  2. php

如何实现同一IP提交表单的次数限制?

第一步,创建表,DDL如下:

CREATE TABLE 
ip_limit
 (
id
 int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
ip
 char(16) NOT NULL DEFAULT '0' COMMENT 'ip地址',
form_id
 int(11) NOT NULL DEFAULT '0' COMMENT '表单id',
last_submit_time
 int(11) NOT NULL DEFAULT '0' COMMENT '上次提交表单时间',
success_submit_times
 int(11) NOT NULL DEFAULT '0' COMMENT '成功提交次数',
  PRIMARY KEY (
id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

第二步,需求逻辑,描述如下:
当用户进行第一次提交时,插入一条记录到ip_limit表,并记住ip,form_id,last_submit_time,success_submit_times等字段信息,当用户进行更多次提交时,先查询对应ip对于指定form_id的last_submit_time,如果current_time – last_submit_time>2*3600,就更新last_submit_time,success_submit_times字段信息,否则提示相关限制信息。

]]>

原创文章,作者:键盘游走者,如若转载,请注明出处:http://www.708034.com/2017/01/%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%90%8c%e4%b8%80ip%e6%8f%90%e4%ba%a4%e8%a1%a8%e5%8d%95%e7%9a%84%e6%ac%a1%e6%95%b0%e9%99%90%e5%88%b6/

发表评论

电子邮件地址不会被公开。 必填项已用*标注