建立一個數據表
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();
在規定的時間內則允許,否則拒絕訪問。