Skip to content

Commit 687a554

Browse files
zeeshan-tfwzeeshan-tfw
andauthored
Added location parameter (#4)
* Added include field, and updated README.md file * Added indentations Co-authored-by: zeeshan-tfw <zeeshan-tfw@gmail.com>
1 parent 905bca5 commit 687a554

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ You need a valid 'IPGeolocation API key' to use this SDK. [Sign up](https://ipge
2424

2525
Internet connection is required to run this component.
2626

27+
## Documentation
28+
Use the following URL to visit documentation
29+
[https://ipgeolocation.io/documentation.html](https://ipgeolocation.io/documentation.html)
30+
31+
2732
## Basic Usage
2833

2934
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.

ip-geolocation-api-php.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?php
2-
$apiKey = "PUT_YOUR_API_KEY_HERE";
2+
$apiKey = "YOUR_API_KEY";
33
$ip = "CLIENT_IP_ADDRESS";
4-
$location = get_geolocation($apiKey, $ip);
4+
$location = get_geolocation($apiKey, $ip, "en", "*", "", $include);
55
$decodedLocation = json_decode($location, true);
66

77
echo "<pre>";
88
print_r($decodedLocation);
99
echo "</pre>";
10-
11-
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
12-
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes;
10+
11+
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "", $include = "") {
12+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes."&include=".$include;
1313
$cURL = curl_init();
14-
1514
curl_setopt($cURL, CURLOPT_URL, $url);
1615
curl_setopt($cURL, CURLOPT_HTTPGET, true);
1716
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
1817
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
1918
'Content-Type: application/json',
2019
'Accept: application/json'
2120
));
21+
2222
return curl_exec($cURL);
2323
}
2424
?>

0 commit comments

Comments
 (0)