PHP code example of suprun-bohdan / laravel-ip-info
1. Go to this page and download the library: Download suprun-bohdan/laravel-ip-info 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/ */
suprun-bohdan / laravel-ip-info example snippets
// Helpers (v4.2+)
$country = client_country();
$country = client_country(default: 'XX');
$city = client_city(); // v4.6+, city edition or when MMDB has city data
// Fluent
if (ip_info()->isCountry('UA', 'PL')) {
// ...
}
$city = ip_info()->city(); // v4.6+
$region = ip_info()->region(); // v4.6+
$tz = ip_info()->timezone(); // v4.6+
$coords = ip_info()->coordinates(); // v4.6+ ['lat' => ..., 'lon' => ...]
// Request macros
$country = request()->clientCountry();
$city = request()->clientCity(); // v4.6+
$ip = request()->clientIp();
// Classic facade
use SuprunBohdan\IpInfo\Laravel\Facades\IpInfo;
IpInfo::for('8.8.8.8')->countryCode();
IpInfo::forRequest(request())->countryCode();
use SuprunBohdan\IpInfo\Laravel\Events\ClientIpBlocked;
Event::listen(ClientIpBlocked::class, function (ClientIpBlocked $event) {
// $event->reason, $event->status, $event->intel
});
use SuprunBohdan\IpInfo\Laravel\Facades\IpInfo;
use SuprunBohdan\IpInfo\Testing\InteractsWithIpInfo;
class ExampleTest extends TestCase
{
use InteractsWithIpInfo;
public function test_country(): void
{
$this->fakeIpInfo(['203.0.113.1' => 'UA']);
$this->assertSame('UA', client_country());
$this->assertTrue(ip_info('203.0.113.1')->isCountry('UA'));
}
}