PHPackages                             davidepastore/ipinfo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. davidepastore/ipinfo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

davidepastore/ipinfo
====================

A wrapper around the ipinfo.io services

v0.7.0(3y ago)55115.2k↓34.8%182GPL-2.0+PHPPHP &gt;=7.0CI failing

Since Oct 9Pushed 3y ago12 watchersCompare

[ Source](https://github.com/DavidePastore/ipinfo)[ Packagist](https://packagist.org/packages/davidepastore/ipinfo)[ RSS](/packages/davidepastore-ipinfo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (2)

ipinfo
======

[](#ipinfo)

[![Latest version](https://camo.githubusercontent.com/9959a6f56e91c843d74d8c29f0e38d8d45d9d2692c91eb2d0e5d80e0b50e4b16/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f446176696465506173746f72652f6970696e666f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DavidePastore/ipinfo)[![Build Status](https://github.com/DavidePastore/ipinfo/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/DavidePastore/ipinfo/actions?query=workflow%3A%22Continuous+Integration%22)[![Coverage Status](https://camo.githubusercontent.com/8293c67c80eaef3b3321d3ba2e9000467deafaf71e36028a309e0d81487bfa16/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f446176696465506173746f72652f6970696e666f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/ipinfo/code-structure)[![Quality Score](https://camo.githubusercontent.com/50c01f2956acb52dcc2f259e0dcdf2954d21d2ace83dee1349205a7e169997ac/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f646176696465706173746f72652f6970696e666f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/ipinfo)[![Total Downloads](https://camo.githubusercontent.com/e395228a3003f9feecddbe77472005e4687854d089043d8b8cb75340155e12eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f446176696465506173746f72652f6970696e666f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DavidePastore/ipinfo)[![PSR2 Conformance](https://camo.githubusercontent.com/c04ccd5a1818b8e9004612cb5cb6c68a7c440d2d1c75ba3eff1123d461d53c46/68747470733a2f2f7374796c6563692e696f2f7265706f732f32343938353631392f736869656c64)](https://styleci.io/repos/24985619/)

A wrapper around the [ipinfo.io](http://ipinfo.io/) services.

Install
-------

[](#install)

You can install the library using [composer](https://getcomposer.org/):

```
$ composer require davidepastore/ipinfo
```

How to use
----------

[](#how-to-use)

### Settings

[](#settings)

#### Token

[](#token)

You can set your token when you instantiate the object but it's not mandatory.

```
$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
	"token" => "your_api_key"
));
```

#### cURL options

[](#curl-options)

The cURL options to use while trying to connect when you instantiate the object:

```
$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
	"curlOptions" => array(
            CURLOPT_CONNECTTIMEOUT => 1,
            CURLOPT_TIMEOUT => 2,
            CURLOPT_CAINFO => __DIR__ . "/cacert.pem"
    )
));
```

### Read details about the given ip

[](#read-details-about-the-given-ip)

You can read all the properties from the given ip.

```
//Get all the properties
$host = $ipInfo->getFullIpDetails("8.8.8.8");

//Get only a single property (this could save bandwidth)
$city = $ipInfo->getSpecificField("8.8.8.8", DavidePastore\Ipinfo\Ipinfo::CITY);
```

### Read details about your ip

[](#read-details-about-your-ip)

You can read all the properties from your ip.

```
//Get all the properties
$host = $ipInfo->getYourOwnIpDetails();

//Get only a single property (this could save bandwidth)
$city = $ipInfo->getYourOwnIpSpecificField(DavidePastore\Ipinfo\Ipinfo::CITY);
```

### Get info from the host

[](#get-info-from-the-host)

After obtaining the `Host` instance you can read all the properties or each of them individually.

```
//Read all the properties
$city = $host->getCity();
$country = $host->getCountry();
$hostname = $host->getHostname();
$ip = $host->getIp();
$loc = $host->getLoc();
$org = $host->getOrg();
$phone = $host->getPhone();
$postal = $host->getPostal();
$region = $host->getRegion();

//Get the associative array with all the properties
$properties = $host->getProperties();
```

### Read only a field

[](#read-only-a-field)

There are different constants that you could use to read specific field value from an `Ipinfo` instance using the `getSpecificField()` and `getYourOwnIpSpecificField()` methods:

```
IpInfo::IP; //For the ip address
IpInfo::HOSTNAME; //For the hostname
IpInfo::LOC; //For the loc
IpInfo::ORG; //For the org
IpInfo::CITY; //For the city
IpInfo::REGION; //For the region
IpInfo::COUNTRY; //For the country
IpInfo::PHONE; //For the phone
IpInfo::POSTAL; //For the postal
IpInfo::GEO; //For the geo info. See the paragraph below for more info
```

### Read only the Geo data (which is faster)

[](#read-only-the-geo-data-which-is-faster)

By using the `getIpGeoDetails()` method you will get less fields. This call tends to be faster than `getFullIpDetails()` so use this call in case you only need the following fields:

```
IpInfo::IP; //For the ip address
IpInfo::CITY; //For the city
IpInfo::REGION; //For the region
IpInfo::COUNTRY; //For the country
IpInfo::PHONE; //For the phone
IpInfo::POSTAL; //For the postal
```

These fields will be empty:

```
IpInfo::HOSTNAME; //For the hostname
IpInfo::LOC; //For the loc
IpInfo::ORG; //For the org
```

### Error Handling

[](#error-handling)

You can handle all the types of IpInfo exceptions by catching the `IpInfoExceptionException`:

```
use DavidePastore\Ipinfo\Exception\IpInfoExceptionException;

try {
    $host = $ipInfo->getFullIpDetails("8.8.8.8");
} catch (IpInfoExceptionException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
```

#### Invalid Token Exception

[](#invalid-token-exception)

It could happen that the token you are using to make the API call is not valid. You can handle it by catching the `InvalidTokenException`:

```
use DavidePastore\Ipinfo\Exception\InvalidTokenException;

try {
    $host = $ipInfo->getFullIpDetails("8.8.8.8");
} catch (InvalidTokenException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
```

#### Rate Limit Exceed Exception

[](#rate-limit-exceed-exception)

It could happen that your API call exceeds the rate limit. You can handle it by catching the `RateLimitExceedException`:

```
use DavidePastore\Ipinfo\Exception\RateLimitExceedException;

try {
    $host = $ipInfo->getFullIpDetails("8.8.8.8");
} catch (RateLimitExceedException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
```

#### Wrong Ip Exception

[](#wrong-ip-exception)

It could happen that your API call is trying to obtain info about a wrong ip. You can handle it by catching the `WrongIpException`:

```
use DavidePastore\Ipinfo\Exception\WrongIpException;

try {
    $host = $ipInfo->getFullIpDetails("qwerty");
} catch (WrongIpException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
```

Issues
------

[](#issues)

If you have issues, just open one [here](https://github.com/DavidePastore/ipinfo/issues).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~299 days

Recently: every ~377 days

Total

11

Last Release

1245d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.3

v0.6.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/11a9e9c18e06a1827a69e0b5e7c4644e1f937f70463ff88b25b76b172be5e769?d=identicon)[DavidePastore](/maintainers/DavidePastore)

---

Top Contributors

[![DavidePastore](https://avatars.githubusercontent.com/u/1949364?v=4)](https://github.com/DavidePastore "DavidePastore (98 commits)")[![rvalitov](https://avatars.githubusercontent.com/u/16267156?v=4)](https://github.com/rvalitov "rvalitov (6 commits)")[![rvanlaak](https://avatars.githubusercontent.com/u/2707563?v=4)](https://github.com/rvanlaak "rvanlaak (2 commits)")[![cmwelsh](https://avatars.githubusercontent.com/u/86490?v=4)](https://github.com/cmwelsh "cmwelsh (1 commits)")[![jamesfairhurst](https://avatars.githubusercontent.com/u/230768?v=4)](https://github.com/jamesfairhurst "jamesfairhurst (1 commits)")

---

Tags

geolocationipipinfophpgeolocationIPipinfo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davidepastore-ipinfo/health.svg)

```
[![Health](https://phpackages.com/badges/davidepastore-ipinfo/health.svg)](https://phpackages.com/packages/davidepastore-ipinfo)
```

###  Alternatives

[torann/geoip

Support for multiple Geographical Location services.

2.2k14.2M76](/packages/torann-geoip)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[s1lentium/iptools

PHP Library for manipulating network addresses (IPv4 and IPv6)

2446.2M24](/packages/s1lentium-iptools)[ipip/db

IPIP.net officially supported IP database ipdb format parsing library

139204.2k6](/packages/ipip-db)[ip2location/ip2location-php

\[Official Release\] IP2Location PHP API to get location info from IPv4 and IPv6 address.

2133.9M33](/packages/ip2location-ip2location-php)[ipinfo/ipinfo

The official PHP library for IPinfo, the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets. Visit our developer docs at https://ipinfo.io/developers.

2891.2M11](/packages/ipinfo-ipinfo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
