File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
2- $ clientIp = "YOUR_CLIENT_IP " ;
3- $ apikey = "YOUR_API_KEY " ;
2+ $ clientIp = "CLIENT_IP_ADDRESS " ;
3+ $ apikey = "PUT_YOUR_API_KEY_HERE " ;
44 $ response = get_location ($ apikey , $ clientIp );
5- $ resArr = array ();
6- $ resArr = json_decode ($ response );
7- echo "<pre> " ; print_r ($ resArr ); echo "</pre> " ;
5+ $ json = array ();
6+ $ json = json_decode ($ response , true );
87
8+ echo "<pre> " ;
9+ print_r ($ json );
10+ echo "</pre> " ;
11+
912 function get_location ($ apiKey , $ ip = null ) {
1013 $ url = "https://api.ipgeolocation.io/ipgeo?apiKey= " .$ apiKey ."&ip= " .$ ip ;
1114 $ cURL = curl_init ();
12-
15+
1316 curl_setopt ($ cURL , CURLOPT_URL , $ url );
1417 curl_setopt ($ cURL , CURLOPT_HTTPGET , true );
18+ curl_setopt ($ cURL , CURLOPT_RETURNTRANSFER , true );
1519 curl_setopt ($ cURL , CURLOPT_HTTPHEADER , array (
1620 'Content-Type: application/json ' ,
1721 'Accept: application/json '
1822 ));
19-
20- $ content = curl_exec ($ cURL );
21- curl_close ($ cURL );
22- return $ content ;
23+ return curl_exec ($ cURL );
2324 }
2425?>
You can’t perform that action at this time.
0 commit comments