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)55117.6k↓46.7%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 3d 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 84% 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

1292d ago

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

v0.6.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1949364?v=4)[Davide Pastore](/maintainers/DavidePastore)[@DavidePastore](https://github.com/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

[zoujingli/ip2region

ip2region v3.0 for PHP - 企业级 IP 地理位置查询库，支持 IPv4 和 IPv6，多种缓存策略，零依赖，开箱即用

1.4k475.0k67](/packages/zoujingli-ip2region)[ipip/db

IPIP.net officially supported IP database ipdb format parsing library

139208.9k6](/packages/ipip-db)[adrianorosa/laravel-geolocation

Laravel Geo Location package to get details for a given IP Address

66101.2k1](/packages/adrianorosa-laravel-geolocation)[ipip/datx

IPIP.net官方支持的IP数据库datx格式解析库

3731.5k1](/packages/ipip-datx)[kartik-v/yii2-ipinfo

An IP address information display widget for Yii 2.0 with country flag and geo position info.

2833.6k1](/packages/kartik-v-yii2-ipinfo)[tastaturberuf/anystores

Location management and geographic search

121.7k](/packages/tastaturberuf-anystores)

PHPackages © 2026

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