ip2location/ip2location-php-api
Composer 安装命令:
composer require ip2location/ip2location-php-api
包简介
PHP module to geolocate the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, MCC, MNC, mobile brand name, elevation and usage type that any IP address or host name originates from.
关键字:
README 文档
README
This project has been merged into IP2Location-PHP-Module. We will no longer maintain and support this project. Please visit IP2Location-PHP-Module for latest updates or enhancements.
This module allows user to geolocate the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, MCC, MNC, mobile brand name, elevation and usage type that any IP address or host name originates from by calling the IP2Location API.
Getting Started
To begin, an API key is required for this module to function. Find further information at https://www.ip2location.com/web-service
Usage
<?php require_once 'class.IP2LocationAPI.php'; $apiKey = 'YOUR_API_KEY'; $package = 'WS25'; // Package: WS1 - WS25 $useSSL = false; // Use HTTP or HTTPS (Secure, but slower) $ip = '8.8.8.8'; // Initialize $location = new IP2LocationAPI($apiKey, $package, $useSSL); /* Translate country, region, and city name to desired language. Refer to product page for available language code. */ $location->setLanguage('zh-cn'); /* Enable add ons to display more result. Refer to product page for available add ons. */ $location->setAddOns([ 'continent', 'country', 'region', 'city', 'geotargeting', 'country_groupings', 'time_zone_info', ]); // Start query if (!$location->query($ip)) { die('ERROR'); } echo '<pre>'; echo 'Country Code : ' . $location->countryCode . "\n"; echo 'Country Name : ' . $location->countryName . "\n"; echo 'Region Name : ' . $location->regionName . "\n"; echo 'City Name : ' . $location->cityName . "\n"; echo 'Latitude : ' . $location->latitude . "\n"; echo 'Longitude : ' . $location->longitude . "\n"; echo 'ZIP Code : ' . $location->zipCode . "\n"; echo 'Time Zone : ' . $location->timeZone . "\n"; echo 'ISP : ' . $location->isp . "\n"; echo 'Domain : ' . $location->domain . "\n"; echo 'Latitude : ' . $location->netSpeed . "\n"; echo 'IDD Code : ' . $location->iddCode . "\n"; echo 'Area Code : ' . $location->areaCode . "\n"; echo 'Weather Station Code : ' . $location->weatherStationCode . "\n"; echo 'Weather Station Name : ' . $location->weatherStationName . "\n"; echo 'Mobile Brand : ' . $location->mobileBrand . "\n"; echo 'Elevation : ' . $location->elevation . "\n"; echo 'Usage Type : ' . $location->usageType . "\n\n"; echo 'Address Type : ' . $location->addressType . "\n\n"; echo 'Category : ' . $location->category . "\n\n"; if ($location->continent) { echo 'Continent Name : ' . $location->continent['name'] . "\n"; echo 'Continent Code : ' . $location->continent['code'] . "\n"; echo 'Hemisphere : ' . $location->continent['hemisphere'] . "\n"; echo 'Localize Name : ' . $location->continent['translated'] . "\n\n"; } if ($location->country) { echo 'Country Name : ' . $location->country['name'] . "\n"; echo 'Localize Name : ' . $location->country['translated'] . "\n"; echo 'Alpha 3 Code : ' . $location->country['alpha3Code'] . "\n"; echo 'Numeric Code : ' . $location->country['numericCode'] . "\n"; echo 'Demonym : ' . $location->country['demonym'] . "\n"; echo 'Flag : ' . $location->country['flag'] . "\n"; echo 'Capital : ' . $location->country['capital'] . "\n"; echo 'Total Area : ' . $location->country['totalArea'] . "\n"; echo 'Population : ' . $location->country['population'] . "\n"; echo 'Currency : ' . $location->country['currencyName'] . ' (' . $location->country['currencyCode'] . ', ' . $location->country['currencySymbol'] . ')' . "\n"; echo 'Language : ' . $location->country['languageName'] . ' (' . $location->country['languageCode'] . ')' . "\n"; echo 'IDD Code : ' . $location->country['iddCode'] . "\n"; echo 'TLD : ' . $location->country['tld'] . "\n\n"; } if ($location->region) { echo 'Region Name : ' . $location->region['name'] . "\n"; echo 'Localize Name : ' . $location->region['translated'] . "\n"; echo 'Region Code : ' . $location->region['code'] . "\n\n"; } if ($location->city) { echo 'City Name : ' . $location->city['name'] . "\n"; echo 'Localize Name : ' . $location->city['translated'] . "\n\n"; } if ($location->geotargeting) { echo 'Metro Code : ' . $location->geotargeting['metro'] . "\n\n"; } if ($location->countryGroupings) { foreach ($location->countryGroupings as $group) { echo 'Group of : ' . $group->name . ' (' . $group->acronym . ')' . "\n"; } echo "\n"; } if ($location->timeZoneInfo) { echo 'Olson : ' . $location->timeZoneInfo['olson'] . "\n"; echo 'Current Time : ' . $location->timeZoneInfo['currentTime'] . "\n"; echo 'GMT Offset : ' . $location->timeZoneInfo['gmtOffset'] . "\n"; echo 'DST : ' . $location->timeZoneInfo['isDST'] . "\n"; } echo '</pre>';
ip2location/ip2location-php-api 适用场景与选型建议
ip2location/ip2location-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 703 次下载、GitHub Stars 达 14, 最近一次更新时间为 2019 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geolocation」 「ip2location」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ip2location/ip2location-php-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ip2location/ip2location-php-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ip2location/ip2location-php-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
The official PHP library for apiip.net that allowing customers to automate IP address validation and geolocation lookup in websites, applications and back-office system. Visit our API docs at https://apiip.net/documentation
A lightweight but powerful IP address lookup database solution to determine visitors country
Supports GeoIP services (sypexgeo.net).
Lookup for visitor's IP information, such as country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type.
[Official Release] IP2Location PHP API to get location info from IPv4 and IPv6 address.
统计信息
- 总下载量: 703
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-15