If its necessary to get GEO-IP data using maxmind service - next function will do the job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | function maxmind_get_data( $ip ) { $query = 'https://geoip.maxmind.com/geoip/v2.1/city/' . $ip; $curl = curl_init($query); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "__YOUR_ID__:__YOUR_KEY__"); //Your credentials goes here curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_ACCEPT_ENCODING, 'application/json'); $resp = curl_exec($curl); if(curl_errno($curl)) { throw new Exception( 'GeoIP request failed with a curl_errno of ' . curl_errno($curl) ); } $result=""; if(!empty($resp)){ $result= json_decode($resp); } return $result; } |
- __YOUR_ID__ - your ID on maxmind service
- __YOUR_KEY__ - your secret key on maxmind service
Be sure that CURL is enabled on your hosting.
