To shield domestic IP addresses, access requires authentication. a foreign trade website wants to shield domestic IP addresses, but we need to manage and allow specific domestic users to access the website. Therefore, authentication is required, how can this function be implemented? Please pay more attention to the first post! Thank you! ------ Solution ------------------ you can create a page. During user access, 1. obtain the user's IP2. then go to the open IP interface to query the user's geographical location (for example, Sina, Netease, and ip shield domestic IP addresses). authentication is required for access.
A foreign trade website wants to shield domestic IP addresses, but we need to manage and allow specific domestic users to access the website. so we need to perform authentication. how can this function be implemented? Please pay more attention to the first post! Thank you!
------ Solution --------------------
You can create a page,
1. get the user's IP address
2. then, go to the open IP interface to query users' geographic locations (for example, Sina, Netease, and ip138 all have open ip address query interfaces)
3. determine whether to block or verify the location of the user.
------ Solution --------------------
PHP code
Function sina ($ ip) {$ php_runtime = microtime (TRUE); $ str = file_get_contents ("http://int.dpool.sina.com.cn/iplookup/iplookup.php? Ip = ". $ ip); $ tmp = explode (" ", $ str); (isset ($ tmp [4]) &! Empty ($ tmp [4])? $ Location ['country'] = $ tmp [4]: $ location ['country'] = null; (isset ($ tmp [5]) &! Empty ($ tmp [5])? $ Location ['city'] = $ tmp [5]: $ location ['city'] = null; (empty ($ tmp [6]) |! Preg_match ("//", $ str) |! Preg_match ("/", $ str ))? $ Location ['sp '] = $ tmp [7]: $ location ['sp'] = $ tmp [6]; $ location ['Time'] = microtime (TRUE) -$ php_runtime; if (! Empty ($ location) return $ location; else return false ;}
------ Solution --------------------
You can use the IP address to determine which subnet the IP belongs, for example, 110.80.0.0/13.
Place all the subnets that can be divided in China into an array and check whether they are in this array.
You do not need to query the address through other interfaces, and then judge the address or carrier name. This is troublesome.
PS: This array is not large, with less than 800 entries.
Please refer to this page for the conversion method: http://url.cn/0TCFrY with all China can be divided into subnets excel download
------ Solution --------------------
Ftp://ftp.apnic.net/public/apnic/stats/apnic/delegated-apnic-latest
Apnic | CN | ipv4 | 180.212.0.0 | 131072 | 20091001 | allocated
This is the domestic analysis and extraction, and then the IP address can be filtered.