djonepl / ipapi-co-php
A simple API for ip-api.com using PHP
1.0.1
2024-02-12 20:31 UTC
Requires
- php: >=5.4
- ext-json: *
Requires (Dev)
- phpunit/phpunit: 5.7
This package is auto-updated.
Last update: 2025-04-12 23:19:38 UTC
README
A simple API for ipapi.co using PHP
Installation
Just require the package using composer.
composer require djonepl/ipapi-co-php
Using the package
Just import, instantiate and call:
<?php use IpApi\IpApi; $api = new IpApi('APIKEY'); $location = $api->lookup('IP');
The \IpApi\Location object
The location object has an schema returned composed by the following fields by default:
ip network version city region region_code country country_name country_code country_code_iso3 country_capital country_tld continent_code in_eu postal latitude longitude timezone utc_offset country_calling_code currency currency_name languages country_area country_population asn org
The location object has some others methods and features:
$location = $api->lookup('8.8.8.8'); // Convert the object to an array $data = $location->toArray(); // Extract city and ASN echo $location->city; // Mountain View echo $location->asn; // AS15169