建立一个数据表
CREATE TABLE `clicks` (
`ip` INT UNSIGNED NOT NULL ,
`time1` INT UNSIGNED NOT NULL ,
`time2` INT UNSIGNED NOT NULL ,
PRIMARY KEY ( `ip` )
) ENGINE = MYISAM
获取ip和当前时间插入到数据表
INSERT INTO clicks (ip,time2) VALUES (INET_ATON(‘{$_SERVER["REMOTE_ADDR"]}‘),UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE time1=time2, time2=UNIX_TIMESTAMP()
再次访问时进行验证
SELECT INET_NTOA(ip) FROM clicks WHERE ip=INET_ATON(‘{$_SERVER["REMOTE_ADDR"]}‘) AND time1+3600-time2+3600<=UNIX_TIMESTAMP();
在规定的时间内则允许,否则拒绝访问。
时间: 2024-12-17 21:59:44