PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   PHP IP Geolocation API Wrapper   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: PHP IP Geolocation API Wrapper
Get IP address location or country information
Author: By
Last change:
Date: 4 years ago
Size: 1,431 bytes


Class file image Download
example usage
ipGEO class ver 1.0

//start the session

//instantiate the class
$ipgeo = new ipgeoWrapper();

The API supports 3 endpoints
An empty endpoint will return all supported country data
An alpha-2 country code will return country data for that country
An IP number will return geo data for the IP number

comment/uncomment the following to test different endpoints. You will need
to use the method with the curl and reset params to bust the cache.
#$endPoint = ''; //get data on all supported countries
#$endPoint = 'US'; //get data on USA
$endPoint = ''; //get geodata on specific ip number

get the response from the api
usage: $ipgeo->getResponse( [string end=null] [,bool curl=true] [,bool reset=false] );
params: end = endpoint [empty] or [ip number] or [country code]
         curl = use curl
         reset = reset session for new request
#$ipgeo->getResponse( $endPoint, true, true );
$ipgeo->getResponse( $endPoint ); //default is to use curl

if( empty($ipgeo->response) ){
'The API did not return a valid response!!!');


Examples to return specific data from the response, you will use...
Continent: $ipgeo->response->continent
Region: $ipgeo->response->region
Country Name: $ipgeo->response->name