PHP code example of black-sheep-tech / laravel-ip-api

1. Go to this page and download the library: Download black-sheep-tech/laravel-ip-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/ */

    

black-sheep-tech / laravel-ip-api example snippets


// Set API Key fluently
$info = IpApi::geolocation()->apiKey('yourapikeyhere')->query('google.com')->get();
// Set Base URL fluently
$info = IpApi::geolocation()->baseUrl('http://ip-api.com/')->query('google.com')->get();

$info = IpApi::geolocation()->disableOverusageProtection()->query('google.com')->get();

use BlackSheepTech\IpApi\IpApi;

$info = IpApi::geolocation()->query('google.com')->get();

//Return Format - can be json, xml, csv, line or php
$info = IpApi::geolocation()->query('google.com')->format('json')->get();

//Return Fields - Supported fields can be found at https://ip-api.com/docs/api:json
$info = IpApi::geolocation()->query('google.com')->fields('countryCode,lat,lon,timezone,query')->get();
// or
$info = IpApi::geolocation()->query('google.com')->fields(['countryCode', 'lat', 'lon', 'timezone', 'query'])->get();

//Return Language - Supported languages can be found at https://ip-api.com/docs/api:json
$info = IpApi::geolocation()->query('google.com')->language('es')->get();

$info = IpApi::geolocation()->query('google.com')->get(true);
//Or
$info = IpApi::geolocation()->query('google.com')->getAsObject();
//When using object return, the format provided is disregarded.
$info = IpApi::geolocation()->query('google.com')->format('php')->getAsObject(); //->format('php') will be ignored and have no impact on the response.

use BlackSheepTech\IpApi\IpApi;

$entities = [
    {
        "query": "google.com"
    },{
        "query": "facebook.com"
    }
];

$info = IpApi::batch()->entities($entities)->get();

use BlackSheepTech\IpApi\IpApi;

$entities = [
    {
        "query": "google.com",
        "fields": "country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,query",
        "lang": "en",
    },{
        "query": "facebook.com",
        "fields": "country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,query",
        "lang": "en",
    }
];

$info = IpApi::batch()->entities($entities)->get();


$entities = [
    {
        "query": "google.com"
    },{
        "query": "facebook.com"
    }
];

$info = IpApi::batch()->entities($entities)->get(true);
//Or
$info = IpApi::batch()->entities($entities)->getAsObject();
bash
php artisan vendor:publish --provider="BlackSheepTech\IpApi\IpApiServiceProvider"