1. Go to this page and download the library: Download taylornetwork/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/ */
php
$response = $geoip->makeRequest('8.8.8.8');
/*
* We need to remove the newline at the end of the response
* or decode will fail due to invalid JSON.
*
* By default this is done in a driver callback function.
*/
$trimmed = trim($response, "\n");
$geoip->decode($trimmed);
// Returns
{#xxx
+"ip": "8.8.8.8",
+"country_code": "US",
+"country_name": "United States",
+"region_code": "CA",
+"region_name": "California",
+"city": "Mountain View",
+"zip_code": "94035",
+"time_zone": "America/Los_Angeles",
+"latitude": 37.386,
+"longitude": -122.0838,
+"metro_code": 807,
}
php
GeoIP::findIP()
bash
$ php artisan geoip:driver DriverName
php
namespace App\GeoIP\Drivers;
use TaylorNetwork\GeoIP\Drivers\Driver;
class DriverName extends Driver
{
/**
* Driver Definition
*
* Set all p://driver-url.com';
$this->responseType = 'JSON';
}
}
php
public function responseCallback($response)
{
// Code to format, etc.
return $response;
}
php
public function findIP ($ip = null)
{
// Code to do HTTP request, and get response...
return $response;
}