ip에 따른 국가 표시 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

ip에 따른 국가 표시 정보

ip에 따른 국가 표시

본문

어떤님이 질문답변에 ip별 분류에 관련된 글 올려서 검색해 보다가 재미난 것을 찾았습니다.

http://www.maxmind.com/app/php
이곳에 가서

Download pure PHP module. Free GeoLite Country and GeoLite City databases are available.

GeoLite Country and GeoLite City 에 들어가면

Binary Format

Our binary format is a highly optimized database that supports fast lookups using our Open Source API code.

아래의 바이너리 포맷을 다운받으세요
국가만 나오게 할 경우 country, 도시까지 나오려면 city 를 다운받으세요

국가는 KR Korea, Republic of 이렇게 나오네요...
도시는 이렇게 나옵니다.
KR KOR Korea, Republic of 11 Seoul-t'ukpyolsi Seoul 37.5664 126.9997
(서울특별시... 처음에 동 이름인가 하고 한참 읽었습니다... 특별시라 적힌거네요 ^^)

다음으로 필요한 것은 1번의 Download 로 들어가서
국가만일 경우
geoip.inc
도시는
geoipcity.inc
geoipregionvars.php

를 다운받습니다.


모두 같은 폴더라고 가정햇을 경우 (아니면 인클루드의 경로수정해주시고요...)
다음과 같은 스크립트를 넣어줍니다.

국가일경우
<?php

include("geoip.inc");

$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);

echo geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "\t" .
     geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "\n";

geoip_close($gi);

?>

도시까지 나올경우

<?php

include("geoipcity.inc");
include("geoipregionvars.php");

$gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);

$record = geoip_record_by_addr($gi,$_SERVER['REMOTE_ADDR']);
print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
print $record->city . "\n";
print $record->postal_code . "\n";
print $record->latitude . "\n";
print $record->longitude . "\n";
print $record->metro_code . "\n";
print $record->area_code . "\n";

geoip_close($gi);

?>


조금 진한 배경을 편집하면 코드만 추출하거나 이름만 추출할 수 있습니다.

국가별 다른 서비스를 하는경우 활용하면 좋을 듯 합니다.
일본이면 일본어 페이지로 중국이면 중국어페이지, 기타 영문페이지 .....

추천
3
  • 복사

댓글 2개

© SIRSOFT
현재 페이지 제일 처음으로