yasir-dev/ip-geolocation

从IP地址获取地理位置信息

v1.0.1 2018-10-04 14:03 UTC

This package is auto-updated.

Last update: 2024-09-05 03:39:45 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

根据用户的IP地址获取地理位置信息。此包使用Geo IP Api来获取地理位置信息。支持IPv4和IPv6。

Diagram

使用限制

Geo IP Api允许每分钟仅150次请求。如果您超过此限制,您的IP将被Geo IP Api阻止。

安装

您可以使用composer安装此包

composer require yasir-dev/ip-geolocation

使用

// use the package
use ipGeolocation\GeoIPLocation;

//get the ip address
$ipAddress = (new GeoIPLocation())->getIpAddress();

// get the location object
$location = (new GeoIPLocation())->getGeoLocation();

//check the status for success
$location->getStatus();

//get the required information
$location->getCountry();
$location->getRegionName();
$location->getRegionCode();
$location->getPostalCode();
$location->getTimezone();
$location->getCurrencyIso();
$location->getCity();
$location->getLongitude();
$location->getLatitude();

//handling error (status fail)
if (!$location->getStatus()) {
    //get error message
    $location->getMessage();
}

使用场景

  • 确定用户的位置。
  • 确定用户的货币/语言。
  • 根据用户的位置自定义您的网站。

贡献

请随时提交新问题、拉取请求、分支或推广此包

许可证

MIT © Yasir Khurshid