2017-12-28 21 views
0

ip를 기반으로하는 모바일 국가 코드를 가져야합니다. 즉, 인도의 경우 => 91, 영국 => 41 등입니다. 아래 코드를 사용했지만 작동하지 않습니다.PHP에서 IP 주소를 사용하여 모바일 국가 코드를 얻는 방법

코드,

$ip = $_SERVER['REMOTE_ADDR']; 
$data = file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip); 
$data = json_decode($data); 
+0

@aniket이 유 오류가 무엇을 얻고있다 –

+0

컬 사용하는 방법을 알려 주시기 바랍니다 수 있습니다 도움이 될 것입니다 소원? –

+0

"모바일 국가 코드"대신 "IDD 국가 코드"를 사용한다고 생각합니다. 내가 맞습니까? –

답변

0

그것은 당신 위는 ISO 코드 국가 geoplugin_countryCode을 얻을 것이다부터

$ip = $_SERVER['REMOTE_ADDR']; 
$data = file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip); 
$data = json_decode($data); 
print_($data); 

Repsone 

{ 
    ["geoplugin_request"]=> 
    string(13) "XX.XX.XX.XXX" 
    ["geoplugin_status"]=> 
    int(200) 
    ["geoplugin_credit"]=> 
    string(143) "Some of the returned data includes GeoLite data created by MaxMind, available from <a href='http://www.maxmind.com'>http://www.maxmind.com</a>." 
    ["geoplugin_city"]=> 
    string(9) "New Delhi" 
    ["geoplugin_region"]=> 
    string(5) "Delhi" 
    ["geoplugin_areaCode"]=> 
    string(1) "0" 
    ["geoplugin_dmaCode"]=> 
    string(1) "0" 
    ["geoplugin_countryCode"]=> 
    string(2) "IN" 
    ["geoplugin_countryName"]=> 
    string(5) "India" 
    ["geoplugin_continentCode"]=> 
    string(2) "AS" 
    ["geoplugin_latitude"]=> 
    string(4) "28.6" 
    ["geoplugin_longitude"]=> 
    string(4) "77.2" 
    ["geoplugin_regionCode"]=> 
    string(2) "07" 
    ["geoplugin_regionName"]=> 
    string(5) "Delhi" 
    ["geoplugin_currencyCode"]=> 
    string(3) "INR" 
    ["geoplugin_currencySymbol"]=> 
    string(7) "&#8360;" 
    ["geoplugin_currencySymbol_UTF8"]=> 
    string(3) "₨" 
    ["geoplugin_currencyConverter"]=> 
    float(64.1725) 
} 

응답

다음주고,

당신이 ISO 국가 코드가되면, u는 쉽게 국가 전화 코드 코드를 얻을 수 있습니다. (양동이 코드와 ISO 코드 맵의 배열 유지) 예

$ country = array ('IN'=> 91, ......);

나는이