1. Go to this page and download the library: Download jetcod/ip-intelligence 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/ */
jetcod / ip-intelligence example snippets
namespace App\Http\Controllers;
use Jetcod\IpIntelligence\GeoIpLookup;
class TestController
{
public function __invoke(GeoIpLookup $lookup)
{
$address = '206.47.249.128';
try {
$ip = $lookup->ip($address);
// Retrieve Language Information
$officialLanguages = $ip->language()->officials();
// Returns an array of official languages spoken in the region, e.g., ['en', 'fr']
$allLanguages = $ip->language()->all();
// Returns an array of all languages spoken in the region, e.g., ['ar', 'atj', 'bla', 'bn', ...]
$locale = $ip->language()->locale;
// Returns the locale for the region, e.g., 'en_CA'
// Retrieve City Information
$cityName = $ip->city()->name;
// Returns the name of the city, e.g., 'Toronto'
// Retrieve Country Information
$countryName = $ip->country()->name;
// Returns the name of the country, e.g., 'Canada'
dd(
"IP Address: $address",
"Official Languages: " . implode(', ', $officialLanguages),
"All Languages: " . implode(', ', $allLanguages),
"Locale: $locale",
"City Name: $cityName",
"Country Name: $countryName"
);
} catch (\Jetcod\IpIntelligence\Exceptions\InvalidIpAddressException $e) {
// Handle the case where the provided IP address is invalid.
echo $e->getMessage();
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {
// Handle the case where the IP address is not found in the database.
echo $e->getMessage();
}
}
}
use Jetcod\IpIntelligence\Models\Language;
use Jetcod\IpIntelligence\Exceptions\LanguageNotFoundException;
use Symfony\Component\Dotenv\Dotenv;
// Create a Language instance for the United States ('US')
$language = new Language('US');
try {
// Retrieve all languages spoken in the United States
$allLanguages = $language->all();
// Retrieve official and de facto official languages
$officialLanguages = $language->officials();
// Retrieve the locale for the first official language
$locale = $language->locale();
// Print the retrieved data
print_r($allLanguages);
print_r($officialLanguages);
echo "Locale: $locale";
} catch (LanguageNotFoundException $e) {
echo $e->getMessage();
}
bash
php artisan IpIntelligence:data-install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.