PHP Classes

PHP Geolocation API ipStack Wrapper: Get the geographic location of a site with ipStack

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 202 All time: 8,465 This week: 524Up
Version License PHP version Categories
ipstack 1.0.0GNU General Publi...5PHP 5, Web services, Geography
Description 

Author

This class can get the geographic location of a site with ipStack.

It can send HTTP requests to the ipStack APi to determine the location of a computer with a given IP address in either the IPV4 and IPV6 formats.

The class can return the IP address location details like the country, region, city and zip.

Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 59
All time rank: 608 in United States United States
Week rank: 47 Up7 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
example usage
ipstackWrapper ver 1.0

You must get an API key from https://ipstack.com/product
and enter it in the ipstack.class.php file
*/

//turning off low level notices
error_reporting(E_ALL ^ E_NOTICE);

//instantiate the class
include('ipstack.class.php');
$ips = new ipsWrapper();

//set our endpoint
//defaults to the api endpoint, but we will set it just to be safe
$ips->setEndPoint('api');

//set the ip number to be checked
$ips->ipnum = '134.201.250.155';

//get the response from the api
$ips->getResponse();

//the reponse property will contain the response returned from the api
echo '<h4>API response for ip: '.$ips->ipnum.'</h4>';
echo
'Country: '.$ips->response->country_name.'<br>';
echo
'Region/State: '.$ips->response->region_name.'<br>';
echo
'City: '.$ips->response->city.'<br>';
echo
'Postal Code: '.$ips->response->zip.'<br>';

//full response
echo '<hr>';
echo
'<h4>Full response</h4>';
echo
'<pre>';
var_dump($ips->response);
echo
'</pre>';

/*
The check endpoint uses the ip number that sent the request
*/

//reset the params
$ips->resetParams();

//set the endpoint to check
$ips->setEndPoint('check');

//request only the main data for the ip number using the fields param
$ips->setParam('fields','main');

//get the response from the api
$ips->getResponse();

//the reponse property will contain the response returned from the api
echo '<h4>API response for originating ip: '.$ips->response->ip.'</h4>';
echo
'<pre>';
var_dump($ips->response);
echo
'</pre>';
?>


  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file example.php Example Usage Example
Plain text file ipstack.class.php Class Main Class
Accessible without login Plain text file license.txt Lic. License

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:202
This week:0
All time:8,465
This week:524Up