Skip to content

Commit 779cca4

Browse files
Update README.md
1 parent 84070f0 commit 779cca4

1 file changed

Lines changed: 28 additions & 31 deletions

File tree

README.md

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
# ip-geolocation-api-php
1+
# IP Geolocation API PHP SDK
2+
You need a valid IPGeolocation API key to use this SDK. Sign up(https://ipgeolocation.io/signup?plan=1) if you don’t have API key.
23

34
## 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);
5+
Call method **get_location($apikey, $clientIp)** passing *API key* and *IP address (optional)* as parameters and it will return IPGeolocation API response.
6+
Note: If you want IP to geolocation for machine calling IPGeolocation API, don't pass the *IP address* parameter.
257

26-
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
27-
'Content-Type: application/json',
28-
'Accept: application/json'
29-
));
30-
31-
$content = curl_exec($cURL);
8+
### Basic Usage
9+
```php
10+
<?php
11+
$clientIp = "IP_ADDRESS";
12+
$apikey = "YOUR_API_KEY";
13+
14+
$response = get_location($apikey, $clientIp);
15+
$resArr = array();
16+
$resArr = json_decode($response);
17+
18+
echo "<pre>"; print_r($resArr); echo "</pre>";
19+
function get_location($apiKey, $ip = null) {
20+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
21+
$cURL = curl_init();
22+
curl_setopt($cURL, CURLOPT_URL, $url);
23+
curl_setopt($cURL, CURLOPT_HTTPGET, true);
3224

33-
curl_close($cURL);
25+
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
26+
'Content-Type: application/json',
27+
'Accept: application/json'
28+
));
3429

35-
return $content;
36-
}
30+
$content = curl_exec($cURL);
31+
curl_close($cURL);
32+
return $content;
33+
}
3734
?>
3835
```

0 commit comments

Comments
 (0)