공공데이터포털(data.go.kr) 의 API를 통한 국가 코드별 접속 제한 방법
$userIp = $_SERVER['REMOTE_ADDR'];
$ch = curl_init();
$url = 'http://apis.data.go.kr/B551505/whois/ipas_country_code'; /*URL*/
/*Service Key*/
$queryParams = '?' . urlencode('serviceKey') . '=*********************************';
$queryParams .= '&' . urlencode('query') . '=' . urlencode($userIp); /**/
$queryParams .= '&' . urlencode('answer') . '=' . urlencode('json'); /**/
curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response);
$country_code = $responseData->response->whois->countryCode;
if($country_code != 'KR')
{
echo "<script>location.replace('https://google.com')</script>";
exit;
}
$ch = curl_init();
$url = 'http://apis.data.go.kr/B551505/whois/ipas_country_code'; /*URL*/
/*Service Key*/
$queryParams = '?' . urlencode('serviceKey') . '=*********************************';
$queryParams .= '&' . urlencode('query') . '=' . urlencode($userIp); /**/
$queryParams .= '&' . urlencode('answer') . '=' . urlencode('json'); /**/
curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response);
$country_code = $responseData->response->whois->countryCode;
if($country_code != 'KR')
{
echo "<script>location.replace('https://google.com')</script>";
exit;
}
총 1명이 반응했습니다
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기
댓글 1개