victorybiz/geoip-location

Get the geographical location of website visitors based on their IP addresses. Support Laravel and PHP (Non-Laravel) Project.

Fund package maintenance!
Patreon

v1.1.9 2021-04-28 11:27 UTC

This package is auto-updated.

Last update: 2021-04-28 11:30:38 UTC


README

GitHub release Software License Build Status Packagist

Get the geographical location of website visitors based on their IP addresses. Support Laravel and PHP (Non-Laravel) Project.

Installation

Install using composer, from the command line run:

$ composer require victorybiz/geoip-location

Laravel Project

Alternatively, you can add "victorybiz/geoip-location": "^1.1" to your composer.json file's require section and then you'll then need to run composer install or composer update to download it and have the autoloader updated.

If you use Laravel >= 5.5 you can skip this step and go to usage

If you use Laravel < 5.5, you need to register the service provider with the application. Open up config/app.php and locate the providers key.

'providers' => [

    Victorybiz\GeoIPLocation\GeoIPLocationServiceProvider::class,

]

And add the GeoIPLocation alias to config/app.php:

'aliases' => [

	'GeoIPLocation' => Victorybiz\GeoIPLocation\Facades\GeoIPLocationFacade::class,

]

Usage in Laravel Project

Please use the GeoIPLocation Facade

use GeoIPLocation;

echo GeoIPLocation::getIP(); // Return client IP

PHP (Non-Laravel) Project

Require the vendor autoload file in your php script.

    require_once 'path/to/vendor/autoload.php';

Usage

Localhost IP 127.0.0.1, 192.168.65.0, 172.18.0.1 and ::1 will return 169.159.82.111 to assert a valid geo response.

    use Victorybiz\GeoIPLocation\GeoIPLocation;

    $geoip = new GeoIPLocation(); 

    // OR

    $geoip = new GeoIPLocation([
        'ip' => null, // Set IP.  Default is NULL, will be auto set by the package
        'baseCurrency' => 'USD', // Set base currency for exchange rate. Default is USD
    ]);

Alternatively

    $geoip = new \Victorybiz\GeoIPLocation\GeoIPLocation();

    // OR

    $geoip = new \Victorybiz\GeoIPLocation\GeoIPLocation([
        'ip' => null, // Set IP.  Default is NULL, will be auto set by the package
        'baseCurrency' => 'USD', // Set base currency for exchange rate. Default is USD
    ]);

You're good to go, explore the package

    echo $geoip->getIP(); // Return client IP

    echo $geoip->setIP('0.0.0.0'); // Set an IP to get its geographical location

    echo $geoip->getCity(); // Return client IP City (null if none)

    echo $geoip->getRegion(); // Return client IP Region (null if none)

    echo $geoip->getRegionCode(); // Return client IP Region Code (null if none)

    echo $geoip->getCountry(); // Return client IP Country

    echo $geoip->getCountryCode(); // Return client IP Country Code

    echo $geoip->getContinent(); // Return client IP Continent 

    echo $geoip->getContinentCode(); // Return client IP Continent Code

    echo $geoip->getPostalCode(); // Return client IP Postal Code (null if none)

    echo $geoip->getLatitude(); // Return client IP Latitude (null if none)

    echo $geoip->getLongitude(); // Return client IP Longitude (null if none)

    echo $geoip->getCurrencyCode(); // Return client IP Country Currency Code (null if none)

    echo $geoip->getCurrencySymbol(); // Return client IP Country Currency Symbol (null if none)

    echo $geoip->getCurrencyExchangeRate(); // Return client IP Country Currency Exchange Rate against NGN (null if none)

    echo $geoip->getLocation(); // Return client IP Location string (city, region, country)

Web Services

Bug Reports and Issue tracking

Kindly make use of the issue tracker for bug reports, feature request, additional web service request and security issues.

License

MIT