PHP code example of reefki / laravel-geoip

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

    

reefki / laravel-geoip example snippets


use Reefki\Geoip\Geoip;

$geoip = Geoip::get('8.8.8.8');
// Or
$geoip = Geoip::get('2001:4860:4860:0:0:0:0:8888');

$geoip->driver; // geojs.
$geoip->ip; // 8.8.8.8
$geoip->city; // Mountain View
$geoip->region; // California
$geoip->country; // United States
$geoip->country_code; // US
$geoip->continent_code; // NA
$geoip->timezone; // America/Chicago
$geoip->latitude; // 37.751
$geoip->longitude; // -97.822
$geoip->cached; // true or false

use Reefki\Geoip\Geoip;

Geoip::get('8.8.8.8', false);

$geoip = $request->geoip(anonymize: true, cache: true);

// 8.8.8.8 = 8.8.8.0
// 2001:4860:4860:0:0:0:0:8888 = 2001:4860:4860::
$anonymizedIp = $request->anonymizedIp();

use Reefki\Geoip\Geoip;

Geoip::driver('geojs')->get('8.8.8.8');

use Reefki\Geoip\Geoip;

Geoip::driver('ip-data')->get('8.8.8.8');
bash
php artisan vendor:publish --provider="Reefki\Geoip\GeoipServiceProvider" --tag="config"