を使用してGEO-IPデータを取得する必要がある場合 maxmindサービス -次の関数がその仕事をします:
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; } |
- __あなたのID__ -maxmindサービスのID
- __YOUR_KEY__ -maxmindサービスの秘密鍵
必ず カール ホスティングで有効になっています。
