PHP code example of ipinfo / ipinfo

1. Go to this page and download the library: Download ipinfo/ipinfo 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 / ipinfo example snippets




pinfo\ipinfo\IPinfo;

$access_token = '123456789abc';
$client = new IPinfo($access_token);
$ip_address = '216.239.36.21';
$details = $client->getDetails($ip_address);

echo $details->city; // Mountain View
echo $details->loc; // 37.4056,-122.0775

$client = new IPinfo();
$ip_address = '216.239.36.21';
$details = $client->getDetails($ip_address);
echo $details->city; // Mountain View
echo $details->loc; // 37.4056,-122.0775

$access_token = '123456789abc';
$client = new IPinfo($access_token);

$details->hostname; // cpe-104-175-221-247.socal.res.rr.com

$details->country; // US
$details->country_name; // United States

$details->is_eu; // False

$details->country_flag['emoji']; // 🇺🇸
$details->country_flag['unicode']; // U+1F1FA U+1F1F8

$details->country_flag_url; // https://cdn.ipinfo.io/static/images/countries-flags/US.svg

$details->country_currency['code']; // USD
$details->country_currency['symbol']; // $

$details->continent['code']; // NA
$details->continent['name']; // North America

$details->loc; // 37.4056,-122.0775
$details->latitude; // 37.4056
$details->longitude; // -122.0775

$details->all;
/*
(
    [ip] => 216.239.36.21
    [hostname] => any-in-2415.1e100.net
    [anycast] => 1
    [city] => Mountain View
    [region] => California
    [country] => US
    [loc] => 37.4056,-122.0775
    [org] => AS15169 Google LLC
    [postal] => 94043
    [timezone] => America/Los_Angeles
    [asn] => Array
        (
            [asn] => AS15169
            [name] => Google LLC
            [domain] => google.com
            [route] => 216.239.36.0/24
            [type] => hosting
        )

    [company] => Array
        (
            [name] => Google LLC
            [domain] => google.com
            [type] => hosting
        )

    [privacy] => Array
        (
            [vpn] => 
            [proxy] => 
            [tor] => 
            [relay] => 
            [hosting] => 1
            [service] => 
        )

    [abuse] => Array
        (
            [address] => US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043
            [country] => US
            [email] => [email protected]
            [name] => Abuse
            [network] => 216.239.32.0/19
            [phone] => +1-650-253-0000
        )

    [domains] => Array
        (
            [ip] => 216.239.36.21
            [total] => 2535948
            [domains] => Array
                (
                    [0] => pub.dev
                    [1] => virustotal.com
                    [2] => blooket.com
                    [3] => go.dev
                    [4] => rytr.me
                )

        )

    [country_name] => United States
    [is_eu] => 
    [country_flag] => Array
        (
            [emoji] => 🇺🇸
            [unicode] => U+1F1FA U+1F1F8
        )

    [country_flag_url] => https://cdn.ipinfo.io/static/images/countries-flags/US.svg
    [country_currency] => Array
        (
            [code] => USD
            [symbol] => $
        )

    [continent] => Array
        (
            [code] => NA
            [name] => North America
        )

    [latitude] => 37.4056
    [longitude] => -122.0775
)

*/

$access_token = '123456789abc';
$settings = ['cache_maxsize' => 30, 'cache_ttl' => 128];
$client = new IPinfo($access_token, $settings);

$access_token = '123456789abc';
$settings = ['cache' => $my_fancy_custom_cache];
$client = new IPinfo($access_token, $settings);

$access_token = '123456789abc';
$settings = ['cache_disabled' => true];
$client = new IPinfo($access_token, $settings);

$access_token = '123456789abc';
$client = new IPinfo($access_token);
$ips = ['1.1.1.1', '8.8.8.8', '1.2.3.4/country'];
$results = $client->getBatchDetails($ips);
echo $results['1.2.3.4/country']; // AU
var_dump($results['1.1.1.1']);
var_dump($results['8.8.8.8']);

countries = [
    "BD" => "Bangladesh",
    "BE" => "Belgium",
    "BF" => "Burkina Faso",
    "BG" => "Bulgaria"
    ...
]

continents = [
        "BD" => ["code" => "AS", "name" => "Asia"],
        "BE" => ["code" => "EU", "name" => "Europe"],
        "BF" => ["code" => "AF", "name" => "Africa"],
        "BG" => ["code" => "EU", "name" => "Europe"],
        "BA" => ["code" => "EU", "name" => "Europe"],
        "BB" => ["code" => "NA", "name" => "North America"]
        ...
]