<?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