Skip to content

Commit 26f8c56

Browse files
committed
Multi-lang and other features support
1 parent 43ccbee commit 26f8c56

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,43 @@ Internet connection is required to run this component.
2626

2727
## Basic Usage
2828

29-
Call method **get_location($apikey, $clientIp)** passing *IP address (optional)* and *API key* as parameters and it will return IP Geolocation API response.
30-
Note: If you want IP to geolocation for the machine calling IPGeolocation API, leave out the *IP address* parameter.
29+
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.
30+
To customize the geolocation response, you can pass the other parameters to **get_geolocation** method as described below:
31+
32+
* $lang
33+
Pass the _language_ parameter to get the geolocation information in a language other than English. By default, it is set to English language.
34+
IPGeolocation provides response in the following languages:
35+
* English (en)
36+
* German (de)
37+
* Russian (ru)
38+
* Japanese (ja)
39+
* French (fr)
40+
* Chinese Simplified (cn)
41+
* Spanish (es)
42+
* Czech (cs)
43+
* Italian (it)
44+
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.
45+
46+
* $fields
47+
Pass the _fields_ parameter to get the specified fields only. By default, it is set to get all the fields in the response.
48+
49+
* $excludes
50+
Pass the _exlcludes_ parameter to get remove the unnecessary fields from the response. By default, it set to not to exclude any fields.
3151

3252
```php
3353
<?php
34-
$clientIp = null;
35-
$apikey = "PUT_YOUR_API_KEY_HERE";
36-
$response = get_location($apikey, $clientIp);
54+
$apiKey = "PUT_YOUR_API_KEY_HERE";
55+
$ip = "CLIENT_IP_ADDRESS";
56+
$response = get_location($apiKey, $ip);
3757
$json = array();
3858
$json = json_decode($response, true);
3959

4060
echo "<pre>";
4161
print_r($json);
4262
echo "</pre>";
4363

44-
function get_location($apiKey, $ip = null) {
45-
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
64+
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
65+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes;
4666
$cURL = curl_init();
4767

4868
curl_setopt($cURL, CURLOPT_URL, $url);
@@ -74,8 +94,8 @@ Here is an example to get the geolocation for a list of IP addresses and display
7494
</style>
7595

7696
<?php
97+
$apiKey = "PUT_YOUR_API_KEY_HERE";
7798
$ips = array("3.3.3.3", "4.4.4.4", "5.5.5.5", "6.6.6.6", "7.7.7.7");
78-
$apikey = "PUT_YOUR_API_KEY_HERE";
7999

80100
echo "<table>";
81101
echo "<tr>";
@@ -85,11 +105,11 @@ Here is an example to get the geolocation for a list of IP addresses and display
85105
echo "<th>Organization</th>";
86106
echo "<th>ISP</th>";
87107
echo "<th>Languages</th>";
88-
echo "<th>Is EU?</th>";
108+
echo "<th>Is EU Member?</th>";
89109
echo "</tr>";
90110

91111
foreach($ips as $ip) {
92-
$location = get_location($apikey, $ip);
112+
$location = get_geolocation($apiKey, $ip);
93113
$decodedLocation = json_decode($location);
94114

95115
echo "<tr>";
@@ -108,8 +128,8 @@ Here is an example to get the geolocation for a list of IP addresses and display
108128
}
109129
echo "</table>";
110130

111-
function get_location($apiKey, $ip = null) {
112-
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
131+
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
132+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes;
113133
$cURL = curl_init();
114134

115135
curl_setopt($cURL, CURLOPT_URL, $url);

ip-geolocation-api-php.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
2-
$clientIp = "CLIENT_IP_ADDRESS";
3-
$apikey = "PUT_YOUR_API_KEY_HERE";
4-
$response = get_location($apikey, $clientIp);
2+
$apiKey = "PUT_YOUR_API_KEY_HERE";
3+
$ip = "CLIENT_IP_ADDRESS";
4+
$response = get_location($apiKey, $ip);
55
$json = array();
66
$json = json_decode($response, true);
77

88
echo "<pre>";
99
print_r($json);
1010
echo "</pre>";
1111

12-
function get_location($apiKey, $ip = null) {
13-
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
12+
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
13+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes;
1414
$cURL = curl_init();
1515

1616
curl_setopt($cURL, CURLOPT_URL, $url);

0 commit comments

Comments
 (0)