Skip to content

Commit 84070f0

Browse files
Merge pull request #1 from irtaza100/master
First commit
2 parents 13f10b0 + b32a87e commit 84070f0

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
# ip-geolocation-api-php
1+
# ip-geolocation-api-php
2+
3+
## Quick Start Guide
4+
5+
There is a methode get_location($apikey, $clientIp) in below given snippet which takes apiKey and clientIp as parameter and returns the response from ipgeolocation.
6+
7+
All you have to do is replace keyword "YOUR_CLIENT_IP" with your valid client ip and "YOUR_API_KEY" with valid apiKey provided by ipgeolocation.
8+
9+
Note: This snippet requires a valid IPGeolocation API key. Sign up (https://ipgeolocation.io/signup?plan=1) if you don’t have API key. And you may leave YOUR_CLIENT_IP empty.
10+
11+
```
12+
<?php
13+
$clientIp = "YOUR_CLIENT_IP";
14+
$apikey = "YOUR_API_KEY";
15+
16+
$response = get_location($apikey, $clientIp);
17+
$resArr = array();
18+
$resArr = json_decode($response);
19+
echo "<pre>"; print_r($resArr); echo "</pre>";
20+
function get_location($apiKey, $ip = null) {
21+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
22+
$cURL = curl_init();
23+
curl_setopt($cURL, CURLOPT_URL, $url);
24+
curl_setopt($cURL, CURLOPT_HTTPGET, true);
25+
26+
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
27+
'Content-Type: application/json',
28+
'Accept: application/json'
29+
));
30+
31+
$content = curl_exec($cURL);
32+
33+
curl_close($cURL);
34+
35+
return $content;
36+
}
37+
?>
38+
```

ip-geolocation-api-php.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
$clientIp = "YOUR_CLIENT_IP";
3+
$apikey = "YOUR_API_KEY";
4+
5+
$response = get_location($apikey, $clientIp);
6+
$resArr = array();
7+
$resArr = json_decode($response);
8+
echo "<pre>"; print_r($resArr); echo "</pre>";
9+
function get_location($apiKey, $ip = null) {
10+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
11+
$cURL = curl_init();
12+
curl_setopt($cURL, CURLOPT_URL, $url);
13+
curl_setopt($cURL, CURLOPT_HTTPGET, true);
14+
15+
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
16+
'Content-Type: application/json',
17+
'Accept: application/json'
18+
));
19+
20+
$content = curl_exec($cURL);
21+
22+
curl_close($cURL);
23+
24+
return $content;
25+
}
26+
?>

0 commit comments

Comments
 (0)