PHP code example of arielmejiadev / geo-ip

1. Go to this page and download the library: Download arielmejiadev/geo-ip 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/ */

    

arielmejiadev / geo-ip example snippets


use ArielMejiaDev\GeoIp\Facades\GeoIp;

GeoIp::country('8.8.8.8');       // 'United States'
GeoIp::countryCode('8.8.8.8');   // 'US'
GeoIp::city('8.8.8.8');          // 'Mountain View'
GeoIp::timezone('8.8.8.8');      // 'America/Los_Angeles'
GeoIp::coordinates('8.8.8.8');   // ['latitude' => 37.386, 'longitude' => -122.084]

$ip = GeoIp::of('8.8.8.8');

$ip->country();      // 'United States'
$ip->is('US');       // true
$ip->isIn(['US', 'CA', 'MX']); // true

// Conditional logic
GeoIp::of($ip)
    ->whenCountry('US', fn ($ip) => handleUs($ip))
    ->whenIn(['MX', 'CO', 'AR'], fn ($ip) => handleLatam($ip))
    ->toArray();

// From the current request
GeoIp::fromRequest()->countryCode();
xml
<env name="GEOIP_DRIVER" value="null"/>