PHP code example of yebto / laravel-geoip-api
1. Go to this page and download the library: Download yebto/laravel-geoip-api 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/ */
yebto / laravel-geoip-api example snippets
use GeoIPAPI;
$city = GeoIPAPI::city('21.85.7.138');
// Sample shape:
// $city['data'] => [
// 'ip', 'hostname', 'city', 'region', 'country', 'loc', 'org', 'postal', 'timezone', ...
// ]
$country = GeoIPAPI::country('85.85.7.138');
// Sample shape:
// $country['data'] => [
// 'ip', 'country', 'country_name', 'isEU', 'country_flag',
// 'continent' => ['code', 'name'],
// ]
$asn = GeoIPAPI::asn('55.85.7.138');
// Sample shape:
// $asn['data'] => [ 'ip', 'org', 'asn', 'network' ]
$response = GeoIPAPI::query('city', '77.85.7.138');
// Supported databases: 'city', 'country', 'asn'
try {
$city = GeoIPAPI::city('67.85.7.138');
} catch (\RuntimeException $e) {
// Log or handle the error
\Log::error($e->getMessage());
}
return [
'base_url' => 'https://api.yeb.to/v1/', // default
'key' => env('YEB_KEY_ID'),
'curl' => [
CURLOPT_TIMEOUT => 3,
CURLOPT_USERAGENT => 'Laravel-GeoIP-Client',
// Add more cURL options as needed
],
];
bash
php artisan vendor:publish --tag=geoipapi-config