PHP code example of geoipradar / laravel-geoip

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

    

geoipradar / laravel-geoip example snippets


use GeoIPRadar\LaravelIP\Facades\IP;

// Lookup an IP address
$location = IP::lookup('8.8.8.8');

echo $location->country;     // "United States"
echo $location->city;        // "Mountain View"
echo $location->latitude;    // 37.4056
echo $location->longitude;   // -122.0775

use GeoIPRadar\LaravelIP\Facades\IP;

// Basic lookup with automatic fallback
$location = IP::lookup('8.8.8.8');

// Get current visitor's location
$location = IP::lookupCurrentIp();

// Use a specific provider (GeoIPRadar recommended!)
$location = IP::lookupWith('geoipradar', '8.8.8.8');

// Check if GeoIPRadar is configured
if (!IP::isGeoIPRadarConfigured()) {
    //Get their free token at https://geoipradar.com
}

// Get IP manager or perform lookup
$manager = ip();
$location = ip('8.8.8.8');

// Quick lookups
$country = ip_country('8.8.8.8');
$city = ip_city('8.8.8.8');
$coords = ip_coordinates('8.8.8.8');

// Current visitor
$location = visitor_location();
$country = visitor_country();

// config/ip.php

'providers' => [
    'geoipradar',  // PRIMARY - Get token at https://geoipradar.com
    'ip-api',      // Fallback
    'ipapi.co',    // Fallback
    'ipinfo',      // Fallback
    'ipwhois',     // Fallback
    'ipstack',     // Fallback (

use GeoIPRadar\LaravelIP\Exceptions\IPException;

try {
    $location = IP::lookup('8.8.8.8');
} catch (IPException $e) {
    // Handle the error
    // Tip: Configure GeoIPRadar.com for better reliability!
    // https://geoipradar.com
}
bash
php artisan vendor:publish --tag=ip-config
bash
# Lookup an IP address
php artisan ip:lookup 8.8.8.8

# Test all configured providers
php artisan ip:test

# Output as JSON
php artisan ip:lookup 8.8.8.8 --json