위토즈 - 개발자프로그램판매공간

정보공유

[API] 아이피로 국가코드 조회


https://xn--c79as89aj0e29b77z.xn--3e0b707e/kor/whois/openAPI_KeyCre.jsp  에서 키값발급.



function check_country_code($ip = '') {


    if (!$ip) {

        return 'KR';

    }


    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, 'http://whois.kisa.or.kr/openapi/ipascc.jsp?query='.$ip.'&key={발급받은키}&answer=json');

    curl_setopt($curl, CURLOPT_VERBOSE, true);

    curl_setopt($curl, CURLOPT_HEADER, false);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($curl, CURLOPT_SSLVERSION, true);

    curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);

    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);

    curl_setopt($curl, CURLOPT_TIMEOUT, 5);

    $result = curl_exec($curl);

    curl_close($curl);


    $code = 'KR';

    if ($result) {

        $json = json_decode($result);

        $code = $json->whois->countryCode;

    }


    return $code;

}





if (!$_SESSION['country_code']) {

    $country_code = check_country_code($_SERVER['REMOTE_ADDR']);

    $_SESSION['country_code'] = $country_code;

    if ($country_code <> 'KR') {

        goto_url(G5_URL.'/index_eng.php');

    }

}