volmaticmw5/ip2location

IP2location wrapper for laravel

dev-main 2021-12-12 14:49 UTC

This package is auto-updated.

Last update: 2025-07-12 23:02:35 UTC


README

A geo-ip ip2location wrapper for laravel

Instructions

In order to use this package, you'll need to download the ip2location databases from https://lite.ip2location.com/ip2location-lite .

After installing the package with composer, simply create a new instance of IP2Location and do whatever you need, e.g.:

use volmaticmw5\IP2Location\IP2Location;

(...)

$ip2location = new IP2Location();
$ip2location->Initialize('mysql', 'geoip_4', 'geoip_6');

Examples

Getting Geo-ip data from a request

$ip2location = new IP2Location();
$ip2location->Initialize('mysql', 'geoip_4', 'geoip_6');
$data = $ip2location->GetGeoDataFromRequest($request);

Getting country code from request

public function GetCountryCode()
{
    $ip2location = new IP2Location();
    $ip2location->Initialize('mysql', 'geoip_4', 'geoip_6');
    $ipNum = $ip2location->getNumericIpFromClientRequest();

    if($ip2location->isIpv6($ipNum))
        return $ip2location->FromIpv6($ipNum);
    else
        return $ip2location->FromIpv4($ipNum);
}