利用本函数可以检查一组IP或IP段是否在禁止列表中
php 代码
- /*
- *PHP IP检查函数
- *Created By 枫行天下
- *E-mail: starlight36@163.com
- *HomePage: http://www.msphome.cn/
- *Last Update: 2009-01-31
- *思路来源于ASP中的一个IP检查函数,原作者已不可考证
- *
- *$userip,要检查的IP,$badiplist,要禁止的IP列表,每个IP用换行符分隔
- *若IP在列表中,返回true,否则返回false
- *IP列表示例
- * 127.0.0.0 #禁止此IP
- * 192.168.1.* #禁止此IP段
- * 10.10.*.10
- * 0.*.0.*
- */
- echo chkip($ip, "127.0.0.1");
php 代码
- //检查IP地址是否在黑名单中
- function chkip($userip, $badiplist) {
- $a_badip = explode("\n",$badiplist);
- $a_ippart = explode(".", $userip);
- if (!is_array($a_badip)) return false;
- for ($i = 0; $i < count($a_badip); $i++) {
- $counter = 0;
- $a_badippart = explode(".", $a_badip[$i]);
- for ($j = 0; $j < count($a_badippart); $j++) {
- if (((string)$a_badippart[$j] == "*") || ((string)$a_ippart[$j] == (string)$a_badippart[$j])) {
- $counter++;
- }
- }
- if ($counter == 4) return true;
- }
- return false;
- }
请问,只允许某IP段访问怎么弄啊