PHP code example of guibranco / ipquery-php

1. Go to this page and download the library: Download guibranco/ipquery-php 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/ */

    

guibranco / ipquery-php example snippets




use GuiBranco\IpQuery\IpQueryClient;

$client = new IpQueryClient();

try {
    $ipQuery = $client->getMyIpData();
    echo "My IP: {$ipQuery->ip}" . PHP_EOL;
    echo "ISP: {$ipQuery->isp->org}" . PHP_EOL;
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . PHP_EOL;
}

$ipData = $client->getIpData('8.8.8.8');
echo "IP: {$ipData->ip}" . PHP_EOL;
echo "Location: {$ipData->location->city}, {$ipData->location->country}" . PHP_EOL;

$multipleIpData = $client->getMultipleIpData(['8.8.8.8', '8.8.4.4']);
foreach ($multipleIpData as $ip) {
    echo "IP: {$ip->ip}, Org: {$ip->isp->org}" . PHP_EOL;
}

class IpQueryResponse {
    public string $ip;
    public Isp $isp;
    public Location $location;
    public Risk $risk;
}

class Isp {
    public string $asn;
    public string $org;
    public string $isp;
}

class Location {
    public string $country;
    public string $country_code;
    public string $city;
    public string $state;
    public string $zipcode;
    public float $latitude;
    public float $longitude;
    public string $timezone;
    public string $localtime;
}

class Risk {
    public bool $is_mobile;
    public bool $is_vpn;
    public bool $is_tor;
    public bool $is_proxy;
    public bool $is_datacenter;
    public int $risk_score;
}
bash
composer