在登录的时候 , 对安全性比较高的业务 , 需要进行限制指定IP或IP段才能登录 , 企邮企业有的就限制只能在本企业内登录
这个时候设计一下数据库 , 实现这个功能可以这样
表结构:
CREATE TABLE `iplimit_list` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `ent_id` int(10) unsigned NOT NULL DEFAULT '0', `start` int(10) unsigned NOT NULL DEFAULT '0', `end` int(10) unsigned NOT NULL DEFAULT '0', `time` int(10) unsigned NOT NULL DEFAULT '0', `type` tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `idx_user` (`ent_id`,`start`,`end`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
start是ip段的开始
end是ip段的结束
都是int数值型的 , 把ip进行转换成long类型
查询的时候可以这样查
select * from iplimit_list where ent_id=23684 and 182322741>=start and 182322741<=end
182322741这个就是当前ip , 大于等于start的ip段 , 小于等于end的ip段
实现的效果