Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/IPGeolocation/ip-geolocation-api-php
IP Geolocation API PHP SDK
https://github.com/IPGeolocation/ip-geolocation-api-php
ip-geolocation-api ip-location php timezone-api
Last synced: 20 days ago
JSON representation
IP Geolocation API PHP SDK
- Host: GitHub
- URL: https://github.com/IPGeolocation/ip-geolocation-api-php
- Owner: IPGeolocation
- License: apache-2.0
- Created: 2018-08-03T11:06:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-31T12:40:01.000Z (over 2 years ago)
- Last Synced: 2024-07-31T19:44:52.524Z (4 months ago)
- Topics: ip-geolocation-api, ip-location, php, timezone-api
- Language: PHP
- Homepage: https://ipgeolocation.io/documentation/ip-geolocation-api-php-sdk-201809051255
- Size: 23.4 KB
- Stars: 32
- Watchers: 7
- Forks: 20
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IP Geolocation API PHP SDK
## Introduction
[IPGeolocation API](https://ipgeolocation.io) is the solution to identify country code (ISO2 and ISO3 standard), country name, continent code, continent name, country capital, state/province, district, city, zip code, latitude and longitude of city, is country belongs to Europian Union, calling code, top level domain (TLD), languages, country flag, internet service provider (ISP), connection type, organization, geoname ID, currency code, currency name, time zone ID, time zone offset, current time in the time zone, is time zone in daylight saving time, and total daylight savings. This document provides important information to help you get up to speed with IPGeolocation API using IP Geolocation API PHP SDK.
Developers can use this PHP SDK for software and web projects related to, but not limited to:
1. Display native language and currency
2. Redirect based on the country
3. Digital rights management
4. Web log stats and analysis
5. Auto-selection of country, state/province and city on forms
6. Filter access from countries you do not do business with
7. Geo-targeting for increased sales and click-through## Quick Start Guide
You need a valid 'IPGeolocation API key' to use this SDK. [Sign up](https://ipgeolocation.io/signup) here and get your free API key if you don't have one.
**Note:** Complete documentation to use this SDK is also available at [IP Geolocation API PHP SDK Documentation](https://ipgeolocation.io/documentation/ip-geolocation-api-php-sdk-201809051255).
## System Requirements
Internet connection is required to run this component.
## Documentation
Use the following URL to visit documentation
[https://ipgeolocation.io/documentation.html](https://ipgeolocation.io/documentation.html)## Basic Usage
Call method **get_geolocation($apiKey, $ip, $lang, $fields, $excludes)** passing _API key_ and _IP address_ as parameters (rest of the parameters are optional) and it will return the Geolocation for the passed IP address.
To customize the geolocation response, you can pass the other parameters to **get_geolocation** method as described below:* $lang
Pass the _language_ parameter to get the geolocation information in a language other than English. By default, it is set to English language.
IPGeolocation provides response in the following languages:
* English (en)
* German (de)
* Russian (ru)
* Japanese (ja)
* French (fr)
* Chinese Simplified (cn)
* Spanish (es)
* Czech (cs)
* Italian (it)
Only the paid plan subscriptions can get the response in languages other than English. All the other users will only get the response in English.* $fields
Pass the _fields_ parameter to get the specified fields only. By default, it is set to get all the fields in the response.* $excludes
Pass the _exlcludes_ parameter to get remove the unnecessary fields from the response. By default, it set to not to exclude any fields.```php
";
print_r($decodedLocation);
echo "";function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes;
$cURL = curl_init();curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
return curl_exec($cURL);
}
?>
```### Example
Here is an example to get the geolocation for a list of IP addresses and display the result as a table:
```php
table, th, tr, td {
border: 1px solid black;
border-collapse: collapse;
}th, td {
padding: 5px 30px;
}";
echo "";
echo "IP";
echo "Continent";
echo "Country";
echo "Organization";
echo "ISP";
echo "Languages";
echo "Is EU Member?";
echo "Currency";
echo "Timezone";
echo "";foreach ($ips as $ip) {
$location = get_geolocation($apiKey, $ip);
$decodedLocation = json_decode($location, true);echo "";
if ($decodedLocation['message'] != '') {
echo "".$ip."";
echo "".$decodedLocation['message']."";
} else {
echo "".$decodedLocation['ip']."";
echo "".$decodedLocation['continent_name']." (".$decodedLocation['continent_code'].")";
echo "".$decodedLocation['country_name']." (".$decodedLocation['country_code2'].")";
echo "".$decodedLocation['organization']."";
echo "".$decodedLocation['isp']."";
echo "".$decodedLocation['languages']."";if ($decodedLocation['is_eu'] == true) {
echo "Yes";
} else {
echo "No";
}
echo "".$decodedLocation['currency']['name']."";
echo "".$decodedLocation['time_zone']['name']."";
}echo "";
}echo "";
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes;
$cURL = curl_init();curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));return curl_exec($cURL);
}
?>
```