Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ You need a valid 'IPGeolocation API key' to use this SDK. [Sign up](https://ipge

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.
Expand Down
12 changes: 6 additions & 6 deletions ip-geolocation-api-php.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
$apiKey = "PUT_YOUR_API_KEY_HERE";
$apiKey = "YOUR_API_KEY";
$ip = "CLIENT_IP_ADDRESS";
$location = get_geolocation($apiKey, $ip);
$location = get_geolocation($apiKey, $ip, "en", "*", "", $include);
$decodedLocation = json_decode($location, true);

echo "<pre>";
print_r($decodedLocation);
echo "</pre>";

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;
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "", $include = "") {
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes."&include=".$include;
$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);
}
?>