PHP code example of playtini / geoip

1. Go to this page and download the library: Download playtini/geoip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

playtini / geoip example snippets


use Playtini\GeoIp\GeoIp;

ho $geoIp->country('8.8.8.8') . "\n"; // US

print_r($geoIp->city('190.0.0.1'));
/*
    [country] => CO
    [city] => Medellín
    [subdivision] => Antioquia
    [subdivision1] => Antioquia
    [subdivision2] =>
    [subdivision3] =>
    [subdivision_code] => ANT
    [postal] => 050021
    [accuracy_radius] => 10
    [latitude] => 6.2529
    [longitude] => -75.5646
    [timezone] => America/Bogota
 */

echo $geoIp->maxMindCountry('190.0.0.1') . "\n"; // CO

print_r($geoIp->maxMindCity('190.0.0.1'));
/*
    [country] => CO
    [city] => Medellín
    [subdivision] => Antioquia
    [subdivision1] => Antioquia
    [subdivision2] =>
    [subdivision3] =>
    [subdivision_code] => ANT
    [postal] => 050021
    [accuracy_radius] => 10
    [latitude] => 6.2529
    [longitude] => -75.5646
    [timezone] => America/Bogota
 */

print_r($geoIp->maxMindAsn('190.0.0.1'));
/*
    [org] => EPM Telecomunicaciones S.A. E.S.P.
    [num] => 13489
    [net] => 190.0.0.0/18
*/

echo $geoIp->ip2LocationCountry('190.0.0.1') . "\n"; // CO

echo $geoIp->ip2LocationProxyType('190.0.0.1') . "\n"; // -
echo $geoIp->ip2LocationProxyType('1.2.3.4') . "\n"; // VPN
echo $geoIp->ip2LocationProxyType('8.8.8.8') . "\n"; // DCH


echo $geoIp->maxMindCountry('80.231.192.1') . "\n"; // CA
echo $geoIp->ip2LocationCountry('80.231.192.1') . "\n"; // DZ

echo $geoIp->country('80.231.192.1') . "\n"; // DZ - IP2Location has higher priority

echo $geoIp->country('80.231.192.1', ['BR', 'MX']) . "\n"; // DZ
// IP2Location still has higher priority, MaxMind country is not among preferred countries

echo $geoIp->country('80.231.192.1', ['CA', 'AU']) . "\n"; // CA
// MaxMind country is among preferred countries; it is used instead of different IP2Location country