\FreeGoIP

A PHP wrapper for FreeGoIP reverse geocoding API.

freegeoip.net is a service providing a public HTTP API for software developers to search the geolocation of IP addresses. It uses a database of IP addresses associated to cities along with other relevant information such as time zone, latitude and longitude. The freegeoip web server is free and open source but the public service limit up to 10,000 queries per hour by default. Once this limit is reached, all requests from the IP will result in HTTP 403, forbidden, until the quota is cleared.

Summary

Methods
Properties
Constants
__construct()
setFormat()
getFormat()
isFormatJSON()
isFormatXML()
isFormatCSV()
setIPAddress()
getIPAddress()
setDomain()
getDomain()
setScheme()
getScheme()
queryReverseGeocoding()
No public properties found
URL_DOMAIN
URL_PATH
URL_HTTP
URL_HTTPS
FORMAT_JSON
FORMAT_XML
FORMAT_CSV
getURLPath()
geocodeURL()
$format
$scheme
$ipaddress
$domain
N/A
No private methods found
No private properties found
N/A

Constants

URL_DOMAIN

URL_DOMAIN

Domain portion of the freeGoIP API URL.

URL_PATH

URL_PATH

URL_PATH Path portion of the freeGoIP API URL.

URL_HTTP

URL_HTTP

HTTP URL of the freeGoIP API.

URL_HTTPS

URL_HTTPS

HTTPS URL of the freeGoIP API.

FORMAT_JSON

FORMAT_JSON

FORMAT_JSON JSON response format.

FORMAT_XML

FORMAT_XML

FORMAT_XML XML response format.

FORMAT_CSV

FORMAT_CSV

FORMAT_CSV CSV response format.

Properties

$format

$format : string

Type

string — Response format (csv,xml,json,jsonp).

$scheme

$scheme : string

Type

string — URL scheme to use (https or http).

$ipaddress

$ipaddress : string

Type

string — IP address to reverse geocode.

$domain

$domain : string

Type

string — Domain to reverse geocode.

Methods

__construct()

__construct(string  $ipaddress = '', string  $domain = '', string  $format = self::FORMAT_JSON) : \FreeGoIP

Constructor. The request is not executed until `queryLocation()` is called.

If neither IP address nor domain is provided, the visitor's IP address is used to reverse geocoding

Parameters

string $ipaddress

IP address to reverse geocode.

string $domain

Domain to reverse geocode (ignored if an IP address is provided).

string $format

optional response format (default: JSON)

Returns

\FreeGoIP

setFormat()

setFormat(string  $format = 'json') : \FreeGoIP

Set the response format to use for reverse geocoding (csv,xml,json,jsonp)

Parameters

string $format

response format

Returns

\FreeGoIP

getFormat()

getFormat() : string

Get the response format to use for reverse geocoding (csv,xml,json,jsonp).

Returns

string —

response format

isFormatJSON()

isFormatJSON() : boolean

Returns whether the current response format is JSON.

Returns

boolean

isFormatXML()

isFormatXML() : boolean

Returns whether the current response format is XML.

Returns

boolean

isFormatCSV()

isFormatCSV() : boolean

Returns whether the current response format is CSV.

Returns

boolean

setIPAddress()

setIPAddress(string  $ipaddress) : \FreeGoIP

Set the IP address to reverse geocode.

Parameters

string $ipaddress

IP address to reverse geocode

Returns

\FreeGoIP

getIPAddress()

getIPAddress() : string

Get the IP address to reverse geocode.

Returns

string —

IP address to reverse geocode

setDomain()

setDomain(string  $domain) : \FreeGoIP

Set the domain to reverse geocode.

Parameters

string $domain

Domain to reverse geocode

Returns

\FreeGoIP

getDomain()

getDomain() : string

Get the domain to reverse geocode.

Returns

string —

domain to reverse geocode

setScheme()

setScheme(string  $scheme) : \FreeGoIP

Set the URL scheme to use.

Parameters

string $scheme

URL scheme to use (https or http)

Returns

\FreeGoIP

getScheme()

getScheme() : string

Get the URL scheme to use.

Returns

string —

URL scheme to use (https or http)

queryReverseGeocoding()

queryReverseGeocoding(boolean  $raw = false, resource  $context = null) : string|array|\SimpleXMLElement

Execute the reverse geocoding request. The return type is based on the requested format: associative array if JSON or CSV, SimpleXMLElement object if XML. If raw is true, the raw string response will be returned.

Queries are performed using cURL and, if not available, using file_get_contents()

Parameters

boolean $raw

whether to return the raw (string) response

resource $context

stream context from stream_context_create()

Returns

string|array|\SimpleXMLElement —

The geocoding response in requested format

getURLPath()

getURLPath() : string

Build the query URL path with all set parameters geocoding request.

Returns

string —

Encoded query string of the timezone request

geocodeURL()

geocodeURL() : string

Build the URL (with query string) of the timezone request.

Returns

string —

URL of the timezone request