PHPackages                             pta/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. [API Development](/categories/api)
4. /
5. pta/ipinfo

ActiveLibrary[API Development](/categories/api)

pta/ipinfo
==========

A basic PHP wrapper for adding IP based user location detection into your application using the IP Info DB API.

0.1.3(9y ago)117MITPHP

Since Apr 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/drparham/IP-User-Location)[ Packagist](https://packagist.org/packages/pta/ipinfo)[ RSS](/packages/pta-ipinfo/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)DependenciesVersions (4)Used By (0)

IP User Location
================

[](#ip-user-location)

A basic PHP wrapper for adding IP based user location detection into your application using the [IP Info DB API](http://ipinfodb.com/ip_location_api.php).

### Installation

[](#installation)

Add `pta/ipinfo` as a requirement to `composer.json`:

```
{
    "require": {
        "pta/ipinfo": "0.1.*"
    }
}
```

Update your packages with `composer update` or install with `composer install`.

You can also add the package using `composer require pta/ipinfo` and later specifying the version you want.

### Methods

[](#methods)

#### Get city based information

[](#get-city-based-information)

You can use `->getCity($ip)` to retrieve city level information about an IP address.

Example json response:

```
{
  "statusCode" : "OK",
  "statusMessage" : "",
  "ipAddress" : "81.149.15.65",
  "countryCode" : "GB",
  "countryName" : "UNITED KINGDOM",
  "regionName" : "ENGLAND",
  "cityName" : "SALISBURY",
  "zipCode" : "SP1 1TP",
  "latitude" : "51.0693",
  "longitude" : "-1.79569",
  "timeZone" : "+01:00"
}

```

#### Get country based information

[](#get-country-based-information)

You can use `->getCountry($ip)` to retrieve country level information about an IP address. Obviously this is faster than retrieving city level information.

Example json response:

```
{
  "statusCode" : "OK",
  "statusMessage" : "",
  "ipAddress" : "81.149.15.65",
  "countryCode" : "GB",
  "countryName" : "UNITED KINGDOM"
}

```

#### Validate an IP address

[](#validate-an-ip-address)

You can use `->validIP($ip)` to see if the specified IP Address is valid.

Under the hood this uses `filter_var($ip, FILTER_VALIDATE_IP)`, I assume this is pretty solid. If you have any suggestions for a better way of doing this send a pull request or [drop me an email](mailto:tom@pta.com).

#### Get the user's IP address

[](#get-the-users-ip-address)

You can use `->getIpAddress()` to retrieve the users IP address.

**You shouldn't be trusting a user based this data, HTTP headers can be faked, trivially.**

### API keys &amp; query limits

[](#api-keys--query-limits)

You can get a (free) API key [here](http://ipinfodb.com/register.php), obviously this should be kept private.

While there are no strict query limits if you send more than 2 requests per second they will be queued. You will still always get a response, but it will be slowed to around 1 /second.

I would strongly suggest using some form of cache. Cookies (mmm cookies) are probably the easiest way to deal with this:

```
// Create a new instance
$ipInfo = new ipInfo (APIKEY, 'json');

// Grab the user location info
$location = json_decode($ipInfo->getCountry($userIP));

// Create a cookie holding the country code for 1 hour (3600 seconds)
setcookie('location', $location['countryCode'], time() + 3600);
```

### Todo

[](#todo)

- Allow devs not to pass an IP address (since it isn't required by the API)
- The `->getIpAddress()` function [probably needs additional testing](http://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php)
- Composer package this badboy

### License

[](#license)

This is open-sourced software licensed under the [MIT license](http://pta.mit-license.org/).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.8% 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 ~95 days

Total

3

Last Release

3535d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57b3fd4aca243a66f2762ca0f4c5c0aa47aa97178e8f04e0e983c43e21c77642?d=identicon)[drparham](/maintainers/drparham)

---

Top Contributors

[![BeingTomGreen](https://avatars.githubusercontent.com/u/1327919?v=4)](https://github.com/BeingTomGreen "BeingTomGreen (44 commits)")[![drparham](https://avatars.githubusercontent.com/u/2704700?v=4)](https://github.com/drparham "drparham (4 commits)")[![OwenMelbz](https://avatars.githubusercontent.com/u/1094740?v=4)](https://github.com/OwenMelbz "OwenMelbz (1 commits)")

### Embed Badge

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

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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