PHP code example of ipinfo / ipinfolaravel
1. Go to this page and download the library: Download ipinfo/ipinfolaravel 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/ */
ipinfo / ipinfolaravel example snippets
protected $middleware = [
...
\ipinfo\ipinfolaravel\ipinfolaravel::class,
];
Route::get('/', function (Request $request) {
$location_text = "The IP address {$request->ipinfo->ip}.";
return view('index', ['location' => $location_text]);
});
'ipinfo' => [
'access_token' => {{access_token}},
],
'ipinfo' => [
'access_token' => env('IPINFO_SECRET'),
],
>>> $request->ipinfo->hostname
cpe-104-175-221-247.socal.res.rr.com
>>> $request->ipinfo->country
US
>>> $request->ipinfo->country_name
United States
>>> $request->ipinfo->all
{
'asn': { 'asn': 'AS20001',
'domain': 'twcable.com',
'name': 'Time Warner Cable Internet LLC',
'route': '104.172.0.0/14',
'type': 'isp'},
'city': 'Los Angeles',
'company': { 'domain': 'twcable.com',
'name': 'Time Warner Cable Internet LLC',
'type': 'isp'},
'country': 'US',
'country_name': 'United States',
'hostname': 'cpe-104-175-221-247.socal.res.rr.com',
'ip': '104.175.221.247',
'ip_address': IPv4Address('104.175.221.247'),
'loc': '34.0293,-118.3570',
'latitude': '34.0293',
'longitude': '-118.3570',
'phone': '323',
'postal': '90016',
'region': 'California'
}
'ipinfo' => [
'cache_maxsize' => {{cache_maxsize}},
'cache_ttl' => {{cache_ttl}},
],
'ipinfo' => [
...
'cache' => new MyCustomCacheObject(),
],
'ipinfo' => [
'ip_selector' => new DefaultIPSelector(),
],
'ipinfo' => [
'ip_selector' => new OriginatingIPSelector(),
],
'ipinfo' => [
...
'ip_selector' => new CustomIPSelector(),
],
'ipinfo' => [
...
'countries_file' => {{countries}},
],
'ipinfo' => [
...
'filter' => false,
],
'ipinfo' => [
...
'filter' => $customFilterFunction,
],
'ipinfo' => [
...
'no_except' => true,
],