|
2 | 2 |
|
3 | 3 | ## Quick Start Guide |
4 | 4 |
|
5 | | - Here is a complete example of code of php curl for ipgeolocation. |
| 5 | + Following is a php code snippet that gets the golocation data from the ip addess given. |
6 | 6 |
|
7 | | - There is a methode get_web_page which takes url as parameter and return response from ipgeolocation. |
| 7 | + There is a methode get_web_page which takes url as parameter and returns the response from ipgeolocation. All you have to do is call the get_web_page function with the correct url |
| 8 | + |
| 9 | + What constitutes a correct URL? |
| 10 | + the correct url is created by |
8 | 11 |
|
9 | 12 | Url takes one required parameter apiKey. |
10 | 13 |
|
11 | | - Note: This Url requires a valid IPGeolocation API key. Sign up if you don’t have one. |
| 14 | + Note: This Url requires a valid IPGeolocation API key. Sign up (https://ipgeolocation.io/signup?plan=1) if you don’t have one. |
12 | 15 |
|
13 | 16 | And replace 103.255.5.105 (ip) with your client ip. |
14 | 17 |
|
15 | 18 | ``` |
16 | 19 | <?php |
17 | | -$response = get_web_page("https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY&ip=103.255.5.105"); |
| 20 | +$response = get_web_page("https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY&ip=YOUR_CLIENTS_IP"); |
| 21 | +
|
18 | 22 | $resArr = array(); |
19 | 23 | $resArr = json_decode($response); |
| 24 | +
|
20 | 25 | echo "<pre>"; print_r($resArr); echo "</pre>"; |
| 26 | +
|
21 | 27 | function get_web_page($url) { |
| 28 | +
|
22 | 29 | $cURL = curl_init(); |
| 30 | + |
23 | 31 | curl_setopt($cURL, CURLOPT_URL, $url); |
24 | 32 | curl_setopt($cURL, CURLOPT_HTTPGET, true); |
25 | | -curl_setopt($cURL, CURLOPT_HTTPHEADER, array( |
| 33 | + |
| 34 | + curl_setopt($cURL, CURLOPT_HTTPHEADER, array( |
26 | 35 | 'Content-Type: application/json', |
27 | 36 | 'Accept: application/json' |
28 | | -)); |
| 37 | + )); |
| 38 | + |
29 | 39 | $content = curl_exec($cURL); |
| 40 | + |
30 | 41 | curl_close($cURL); |
| 42 | + |
31 | 43 | return $content; |
32 | 44 | } |
33 | 45 | ?> |
|
0 commit comments