난 해외 안나간다.
그래서, 내 id는 한국에서만 접속하게 하고 싶다?
좋은 생각 입니다.
회원 선택으로 한국 ip 접속만 가능하게 하는 기능 (현재는 은행/카드사만 제공) 추가 들어 갑니다.
해킹은 주로 외국에서 접속을 시도 하므로, 한국 ip 접속 기능 추가하면 쉽게 못 들어 옵니다.
g4_geoip 테이블을 만들어 줍니다.
CREATE TABLE IF NOT EXISTS `g4_geoip` (
`ip_start` char(15) NOT NULL,
`ip_end` char(15) NOT NULL,
`ip32_start` int(10) unsigned NOT NULL,
`ip32_end` int(10) unsigned NOT NULL,
`country_code` char(2) NOT NULL,
`country_full` varchar(50) NOT NULL,
KEY `ip32` (`ip32_start`,`ip32_end`)
)
`ip_start` char(15) NOT NULL,
`ip_end` char(15) NOT NULL,
`ip32_start` int(10) unsigned NOT NULL,
`ip32_end` int(10) unsigned NOT NULL,
`country_code` char(2) NOT NULL,
`country_full` varchar(50) NOT NULL,
KEY `ip32` (`ip32_start`,`ip32_end`)
)
함수를 추가 합니다. lib/common.php나 적당한 곳에 하면 됩니다.
불당팩은 b4.lib.php에 들어 있습니다.
// ip 주소를 unit 32 숫자로
// http://www.zedwood.com/article/144/php-mysql-geoip-lookup
function ipaddress_to_uint32($ip) {
list($v4,$v3,$v2,$v1) = explode(".", $ip);
return ($v4*256 *256*256) + ($v3*256*256) + ($v2*256) + ($v1);
}
// http://www.zedwood.com/article/144/php-mysql-geoip-lookup
function ipaddress_to_uint32($ip) {
list($v4,$v3,$v2,$v1) = explode(".", $ip);
return ($v4*256 *256*256) + ($v3*256*256) + ($v2*256) + ($v1);
}
// ip의 국가명을 return
// http://www.zedwood.com/article/144/php-mysql-geoip-lookup
function ipaddress_to_country_code($ip) {
global $g4;
// http://www.zedwood.com/article/144/php-mysql-geoip-lookup
function ipaddress_to_country_code($ip) {
global $g4;
$i = ipaddress_to_uint32($ip);
$query = "select * from $g4[geoip_table] where ip32_start<= $i and $i <=ip32_end;";
$result = sql_fetch($query);
return $result['country_code'];
}
$result = sql_fetch($query);
return $result['country_code'];
}
common.php에 사용을 위한 함수를 추가 합니다.
// geoip 체크, 한국이면 KR이 리턴 됩니다.
$geoip = ipaddress_to_country_code($_SERVER['REMOTE_ADDR']);
한국 ip만 접속가능하게 하려면,
$geoip == "KR" 인 경우만 접속하게 하고, 나머지는 die 시킴 됩니다.
이 기능을 잘 이용하면,
중국/필리핀/인도네시아 같은 나라의 ip 차단도 할 수 있습니다.
하지만, 모든 ip 대역 체크는 geoip 갯수가 15만을 넘기 때문에 부적절 합니다.
대형 회사만 빼고. ㅎㅎ
===
g4_geoip에 데이터를 업로드 하는 것은 한국꺼만 할수도 전체를 다 할 수도 있습니다.
한국 ip db는 아래주소에서 최신 것을 받은 후 excel에서 정렬해서 한국꺼만 골라서 씁니다.
할당된거 회수하지는 않고, 신규 부여도 가끔 되므로, db를 한번 올리면 한동안 잘 쓸 수 있습니다.
한국 ip만 분리해둔거
참조문서
- opencode.co.kr -