2017 © Pedro Peláez
 

library ip-user-location

A basic PHP wrapper for integrating IP based user location detection into your application.

image

danio1024/ip-user-location

A basic PHP wrapper for integrating IP based user location detection into your application.

  • Monday, December 2, 2013
  • by danio1024
  • Repository
  • 2 Watchers
  • 0 Stars
  • 474 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 21 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

IP User Location

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

Methods

Get city based information

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

Example json response:, (*3)

{
  "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

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

Example json response:, (*5)

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

Validate an IP address

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

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., (*7)

Get the user's IP address

You can use ->getIpAddress() to retrieve the users IP address., (*8)

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

API keys & query limits

You can get a (free) API key here, obviously this should be kept private., (*10)

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., (*11)

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

// 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

License

This is open-sourced software licensed under the MIT license., (*13)

The Versions

02/12 2013

dev-master

9999999-dev http://github.com/danio1024/IP-User-Location

A basic PHP wrapper for integrating IP based user location detection into your application.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Daniel Remiszewski

ip location

02/12 2013

dev-1.0.x-dev

dev-1.0.x-dev http://github.com/danio1024/IP-User-Location

A basic PHP wrapper for integrating IP based user location detection into your application.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Daniel Remiszewski

ip location