第1步、把下面的代码加入到 /e/class/uesrfun.php 中。 其中tinyipdata.dat,是用的discuz x2的最新IP数据库,自行拷贝到/e/class/ipdata/目录下。 wry.dat,这个IP数据库不要管,运行不到 最后的/index.html,自行修改成自己的默认首页文件名。
 
  //获取IP的地理位置 function infoip($ip) {
          $return = '';
          if(preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $ip)) {
                  $iparray = explode('.', $ip);
                  if($iparray[0] == 10 || $iparray[0] == 127 || ($iparray[0] == 192 && $iparray[1] == 168) || ($iparray[0] == 172 && ($iparray[1] >= 16 && $iparray[1] <= 31))) {                         $return = 'LAN';                 } elseif($iparray[0] > 255 || $iparray[1] > 255 || $iparray[2] > 255 || $iparray[3] > 255) {                         $return = 'Invalid IP Address';                 } else {                         $tinyipfile = dirname(__FILE__).'../ipdata/tinyipdata.dat';                         $fullipfile = dirname(__FILE__).'../ipdata/wry.dat';                         if(@file_exists($tinyipfile)) {                                 $return = convertip_tiny($ip, $tinyipfile);                         } elseif(@file_exists($fullipfile)) {                                 $return = convertip_full($ip, $fullipfile);                         }                 }         }
          return $return;
  }
  function convertip_tiny($ip, $ipdatafile) {
          static $fp = NULL, $offset = array(), $index = NULL;
          $ipdot = explode('.', $ip);         $ip    = pack('N', ip2long($ip));
          $ipdot[0] = (int)$ipdot[0];         $ipdot[1] = (int)$ipdot[1];
          if($fp === NULL && $fp = @fopen($ipdatafile, 'rb')) {                 $offset = @unpack('Nlen', @fread($fp, 4));                 $index  = @fread($fp, $offset['len'] - 4);         } elseif($fp == FALSE) {                 return  'Invalid IP data file';         }
          $length = $offset['len'] - 1028;         $start  = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
          for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
                  if ($index{$start} . $index{$start + 1} . $index{$start + 2} . $index{$start + 3} >= $ip) {                         $index_offset = @unpack('Vlen', $index{$start + 4} . $index{$start + 5} . $index{$start + 6} . "\x0");                         $index_length = @unpack('Clen', $index{$start + 7});                         break;                 }         }
          @fseek($fp, $offset['len'] + $index_offset['len'] - 1024);         if($index_length['len']) {                 return @fread($fp, $index_length['len']);         } else {                 return 'Unknown';         }
  }
  function allowip($local){         $userip = egetip();         $_tmpare = '';         $_tmpare = infoip($userip);         $pos = strpos($_tmpare, $local);         if($pos === false) {                 printerror('BlackIP', '/index.html', 1);         } }
  function blackip($local){         $userip = egetip();         $_tmpare = '';         $_tmpare = infoip($userip);         $pos = strpos($_tmpare, $local);         if($pos !== false) {                 printerror('BlackIP', '/index.html', 1);         } }
 
  第2步、在 /e/DoInfo/ecms.php 文件里加入一下代码: allowip,是可以通过的IP,blackip,是不允许通过的IP。如下,则是江苏(除去苏州)的IP可以提交信息
  //限制发布信息的IP allowip("江苏"); blackip("苏州"); .......
 
 
  第3步、在 /e/data/language/gb/pub/q_message.php 下面加上语言包里的提示信息:
  'BlackIP'=>'您的IP不允许发布信息', 
								 |