摘要:獲取地址信息之前用過新浪淘寶的接口,但如果新浪淘寶接口出問題就沒法用了,而且網絡獲取也慢今天介紹一個開源的淘寶接口中國華北北京市北京市電信純真數據庫先下文件安裝使用百度來自北京市北京亞洲中國中國中國中國北京市
PHP 獲取 ip 地址信息之前用過新浪/淘寶的接口,但如果新浪/淘寶接口出問題就沒法用了,而且網絡獲取也慢.
今天介紹一個開源的geoip
$ip = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=180.149.132.47"); print_r(json_decode($ip, 1)); Array ( [code] => 0 [data] => Array ( [country] => 中國 [country_id] => CN [area] => 華北 [area_id] => 100000 [region] => 北京市 [region_id] => 110000 [city] => 北京市 [city_id] => 110100 [county] => [county_id] => -1 [isp] => 電信 [isp_id] => 100017 [ip] => 180.149.132.47 ) )純真 IP 數據庫
// 先下文件 QQWry.Dat http://www.cz88.net/fox/ http://update.cz88.net/soft/setup.zip $IpLocation = new IpLocation("qqwry/QQWry.Dat"); $client = $IpLocation->getlocation("180.149.132.47");安裝 geoip
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/bin/composer chmod +x composer composer require geoip2/geoip2:~2.0使用
require_once "vendor/autoload.php"; use GeoIp2DatabaseReader; $reader = new Reader("GeoIP2-City.mmdb"); $record = $reader->city("180.149.132.47");// 百度 ip dump($record);// dump 來自 laravel City {#1899 ▼ #city: City {#1908 ?} #location: Location {#1909 ?} #postal: Postal {#1910 ?} #subdivisions: array:1 [?] #continent: Continent {#1902 ?} #country: Country {#1903 ?} #locales: array:1 [?] #maxmind: MaxMind {#1904 ?} #registeredCountry: Country {#1905 ?} #representedCountry: RepresentedCountry {#1906 ?} #traits: Traits {#1907 ?} #raw: array:7 [▼ "city" => array:2 [▼ "geoname_id" => 1816670 "names" => array:8 [▼ "de" => "Peking" "en" => "Beijing" "es" => "Pekín" "fr" => "Pékin" "ja" => "北京市" "pt-BR" => "Pequim" "ru" => "Пекин" "zh-CN" => "北京" ] ] "continent" => array:3 [▼ "code" => "AS" "geoname_id" => 6255147 "names" => array:8 [▼ "de" => "Asien" "en" => "Asia" "es" => "Asia" "fr" => "Asie" "ja" => "アジア" "pt-BR" => "ásia" "ru" => "Азия" "zh-CN" => "亞洲" ] ] "country" => array:3 [▼ "geoname_id" => 1814991 "iso_code" => "CN" "names" => array:8 [▼ "de" => "China" "en" => "China" "es" => "China" "fr" => "Chine" "ja" => "中國" "pt-BR" => "China" "ru" => "Китай" "zh-CN" => "中國" ] ] "location" => array:4 [▼ "accuracy_radius" => 50 "latitude" => 39.9289 "longitude" => 116.3883 "time_zone" => "Asia/Shanghai" ] "registered_country" => array:3 [▼ "geoname_id" => 1814991 "iso_code" => "CN" "names" => array:8 [▼ "de" => "China" "en" => "China" "es" => "China" "fr" => "Chine" "ja" => "中國" "pt-BR" => "China" "ru" => "Китай" "zh-CN" => "中國" ] ] "subdivisions" => array:1 [▼ 0 => array:3 [▼ "geoname_id" => 2038349 "iso_code" => "11" "names" => array:3 [▼ "en" => "Beijing" "fr" => "Municipalité de Pékin" "zh-CN" => "北京市" ] ] ] "traits" => array:1 [▼ "ip_address" => "180.149.132.47" ] ] } print($record->country->isoCode . " "); // "CN" print($record->country->name . " "); // "China" print($record->country->names["zh-CN"] . " "); // "中國 " print($record->mostSpecificSubdivision->name . " "); // "Beijing" print($record->mostSpecificSubdivision->isoCode . " "); // "11" print($record->city->name . " "); // "Beijing " print($record->location->latitude . " "); // 39.9289 print($record->location->longitude . " "); // 116.3883ip2region
php binding/php/testSearcher ./data/ip2region.db p2region>> 101.105.35.57 2163|中國|華南|廣東省|深圳市|鵬博士 in 0.02295 millseconds
公眾號:蘇生不惑
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/23346.html
摘要:總結在作為反向代理的架構中,的其他語言也是類似的名稱拿到的將會是代理的地址。本意就是遠程的地址,是代理層,轉發請求到,獲取到的遠程地址實際上是反向代理服務器,這是符合協議規則的。 nginx反向代理后,在應用中取得的ip都是反向代理服務器的ip,取得的域名也是反向代理配置的url的域名,解決該問題,需要在nginx反向代理配置中添加一些配置信息,目的將客戶端的真實ip和域名傳遞到應用程...
摘要:總結在作為反向代理的架構中,的其他語言也是類似的名稱拿到的將會是代理的地址。本意就是遠程的地址,是代理層,轉發請求到,獲取到的遠程地址實際上是反向代理服務器,這是符合協議規則的。 nginx反向代理后,在應用中取得的ip都是反向代理服務器的ip,取得的域名也是反向代理配置的url的域名,解決該問題,需要在nginx反向代理配置中添加一些配置信息,目的將客戶端的真實ip和域名傳遞到應用程...
摘要:獲取地址新浪接口根據查詢所在區域信息淘寶接口根據查詢所在區域信息 獲取IP地址: function getIP(){ if (isset($_SERVER)) { if (isset($_SERVER[HTTP_X_FORWARDED_FOR])) { $realip = $_SERVER[HTTP_X_FORWARDED_FOR]; ...
在網上有很多的根據ip地址獲取實際地址的教程 他們給了很多的現成接口,例: 新浪:http://int.dpool.sina.com.cn/... . $ip 淘寶:http://ip.taobao.com/service/getIpInfo.php?ip=.$ip 等接口去根據ip地址獲取實際地址的接口,但是這些接口十分的不穩定,這里我推薦百度地圖的根據ip獲取實際地址的接口,經過測試,速度杠杠...
閱讀 2907·2021-11-19 09:40
閱讀 3578·2021-10-09 09:43
閱讀 2675·2021-09-22 15:31
閱讀 1724·2021-07-30 15:31
閱讀 782·2019-08-30 15:55
閱讀 3257·2019-08-30 15:54
閱讀 1161·2019-08-30 11:26
閱讀 1907·2019-08-29 13:00