yasir-dev/ip-geolocation

Get geo location information from IP address

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

This package is auto-updated.

Last update: 2024-10-05 03:53:04 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

Get geolocation information based on the IP address of the user. This package uses Geo IP Api to get geo information. Both IPv4 and IPv6 are supported.

Diagram

Usage limits

Geo IP Api allows only 150 requests per minute. If you exceed this limit your Ip will be blocked by Geo IP Api

Installation

You can install the package using composer

composer require yasir-dev/ip-geolocation

Usage

// 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();
}

Use Cases

  • Determine user's location.
  • Determine user's currency/language.
  • Customise your website based on user's location.

Contribution

Please feel free to open new issues, pull requests, fork or spread the package

License

MIT © Yasir Khurshid