Mybb注册地域限制插件

上一篇文件关于Mybb注册地域限制的文章是在web前端实现,需要javascript的支持,如果用户限制javascript的运行就不可以了,特别是一些东欧国家所用浏览器非常古老,他们不自觉地就突破了web前端的限制,没有办法,只好办后台。代码如下:
<?php
/**
 *用户IP地址检测,拒绝非湖北省用户
 *Author:cai21cn
 *
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("datahandler_user_validate", "ipcheck_end");

function ipcheck_info()
{
	return array(
		"name"=> "ipcheck",
		"description"=>"检测注册用户IP合法性",
		"website"=> "",
		"author"=>"cai21cn",
		"authorsite"=> "",
		"version"=> "1.0",
		"compatibility" =>"*",
		"guid"=>"",
	);
}



function ipcheck_end(&$user)
{
	global $mybb, $lang;
		// if we created the user registration detection, check it!
	
	   if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
	
	$file = iconv("GBK","UTF-8",file_get_contents("http://whois.pconline.com.cn/ip.jsp?ip=".$ip));
			
		
  		  if (strpos($file,"湖北")===false){
  				  //$user->set_error($file." * 1抱歉,仅限湖北省内用户注册!".$ip);
				  $user->set_error("抱歉,仅限湖北省内用户注册!");
			  }else{
				//  $user->set_error($file." * 2抱歉,仅限湖北省内用户注册!".$ip);
				  }
   }

?>


插件的安装使用请参阅www.mybb.com

猜你喜欢

转载自cai21cn.iteye.com/blog/1262755