Find the location of our ip address based on the ip address. The easiest way is to directly search the ip address in Baidu to know the location of your ip address, but we cannot use this method for some websites, but it can be implemented through APIs. example: use a third-party interface instance to replace... find the location of our ip address based on the ip address. The easiest way is to directly search the ip address in Baidu to know the location of your ip address, but we cannot use this method for some websites, but it can be implemented through APIs.
For example, the code for using a third-party interface instance is as follows:
(.*?)/", $ Str, $ addr1); // final result, 2; $ addr = $ ip. "=> ". $ addr1 [1] [0]; echo $ addr ;}?>
For example, QQWry currently only supports PHP5.
Installation:
1. sudo pecl install qqwry-beta or directly download and compile phpize &./configure & make & sudo make install
2. edit php. ini and add extension = qqwry. so.
3. restart the http server
It is easy to use. The first step is to instantiate the file path of the pure database, and then call the q method. this method returns an array. The first value is Address 1, for example, Nanning, the second value is Address 2, for example, Suining telecom ADSL. you can see it clearly ., The iconv below is to convert data from GB2312 to UTF-8, if your site is using GB2312, then this step is not needed, the code is as follows:
Q ('2017. 0.0.1 '); $ addr1 = iconv ('gb2312', 'utf-8', $ addr1); $ addr2 = iconv ('gb2312', 'utf-8 ', $ addr2); echo $ addr1, '|', $ addr2, ""; $ arr = $ qqwry-> q ('2017. 222. 216.47.4 '); $ arr [0] = iconv ('gb2312', 'utf-8', $ arr [0]); $ arr [1] = iconv ('gb2312', 'utf-8', $ arr [1]); echo $ arr [0], '| ', $ arr [1], ""; $ arr = $ qqwry-> q ('64. 233.187.99 '); $ arr [0] = iconv ('gb2312', 'utf-8', $ arr [0]); $ arr [1] = iconv ('gb2312', 'utf-8', $ arr [1 ]); Echo $ arr [0], '|', $ arr [1], ""; // output: // address of the local machine | // Nanning, Guangxi | (Qingxiu district) china Telecom ADSL // US | Google, California?>
For example, if you only need to check the IP address, it does not need to be as complicated as that. for example, if I enter 110.110.110.110 in Baidu
Display address: IP address: 110.110.110.110 Harbin Tietong, Heilongjiang province