geoip_record_by_name

(PECL geoip >= 0.2.0)

geoip_record_by_name返回 GeoIP 數(shù)據(jù)庫(kù)中詳細(xì)的城市信息

說(shuō)明

geoip_record_by_name(string $hostname): array

geoip_record_by_name() 函數(shù)將會(huì)返回主機(jī)或者 IP 地址所對(duì)應(yīng)的記錄信息。

該函數(shù)在 GeoLite City 版本和商業(yè) GeoIP City 版本中可用。 版本不對(duì)的話,將會(huì)拋出一個(gè)警告。

返回的關(guān)聯(lián)數(shù)組不同的鍵名對(duì)應(yīng)如下:

  • "continent_code" -- 由兩個(gè)字符組成的洲簡(jiǎn)稱。(要求 GeoIP 的庫(kù)版本是1.0.4以上)
  • "country_code" -- 由2個(gè)字母組成的國(guó)家簡(jiǎn)稱。(參見 geoip_country_code_by_name())
  • "country_code3" -- 由三個(gè)字母組成的國(guó)家簡(jiǎn)稱。(參見 geoip_country_code3_by_name())
  • "country_name" -- 國(guó)家名稱 (參見 geoip_country_name_by_name())
  • "region" -- 地區(qū)代碼 (比如: CA 對(duì)應(yīng) California)
  • "city" -- 城市名稱。
  • "postal_code" -- 郵編,F(xiàn)SA 或者 Zip 編碼。
  • "latitude" -- 有符號(hào)的雙精度緯度。
  • "longitude" -- 有符號(hào)的雙精度經(jīng)度。
  • "dma_code" -- 指定市場(chǎng)區(qū)號(hào) (只支持美國(guó)和加拿大)
  • "area_code" -- PSTN (公共交換電話網(wǎng)絡(luò))地區(qū)代碼。 (比如: 212)

參數(shù)

hostname

所要查找的主機(jī)或者 IP 地址。

返回值

成功,返回關(guān)聯(lián)數(shù)組,未找到相關(guān)信息則返回 false 。

更新日志

版本 說(shuō)明
1.0.4 給 GeoIP 1.4.4及以上版本的庫(kù)添加 continent_code 字段。
1.0.3 添加 country_code3 和 country_name 字段。

范例

示例 #1 geoip_record_by_name() 例子:

以下例程將會(huì)輸出包含 example.com 主機(jī)記錄的數(shù)組。

<?php
$record 
geoip_record_by_name('www.example.com');
if (
$record) {
    
print_r($record);
}
?>

以上例程會(huì)輸出:

Array
(
    [continent_code] => NA
    [country_code] => US
    [country_code3] => USA
    [country_name] => United States
    [region] => CA
    [city] => Marina Del Rey
    [postal_code] => 
    [latitude] => 33.9776992798
    [longitude] => -118.435096741
    [dma_code] => 803
    [area_code] => 310
)