PHP Classes

PHP Geo Location by Internet Protocol API: Find the geographical location by remote IP Number

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 255 This week: 1All time: 7,853 This week: 560Up
Version License PHP version Categories
ipapi 1.1GNU General Publi...5PHP 5, Web services, Geography
Description 

Author

This class is a wrapper for the ipAPI geolocation service provided by apiLayer.

It can send HTTP requests to the ipAPI Web server to request location information for a given IP address.

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

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: 58
All time rank: 618 in United States United States
Week rank: 21 Up4 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Recommendations

I want to get users location from where they are browsing.
Get user's location from where they are browsing.

Example

<?php
/*
example usage
ipapiWrapper ver 1.0

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

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

//instantiate the class
include('ipapi.class.php');
$ips = new ipapiWrapper();

//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  
File Role Description
Accessible without login Plain text file example.php Example Example Usage
Plain text file ipapi.class.php Class Main Class
Accessible without login Plain text file license.txt Lic. License

 Version Control Unique User Downloads Download Rankings  
 0%
Total:255
This week:1
All time:7,853
This week:560Up