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: 1 year ago
Size: 1,431 bytes
 

Contents

Download
<?php
/*
example usage
ipGEO class ver 1.0
*/

//start the session
session_start();

//instantiate the class
include('ipgeo.class.php');
$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 = '91.213.103.0'; //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) ){
    die(
'The API did not return a valid response!!!');
}

echo
'<pre>';
var_dump($ipgeo->response);
echo
'</pre>';

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


For more information send a message to info at phpclasses dot org.