아이피 위치추적 (ISP 위치 정보)

function get_ipinfo($ip)
{
if ($ip == "") return false;
$sql = "SELECT * FROM typing_ipinfo WHERE ii_ip = '".$ip."'";
$row = sql_fetch($sql);
if ($row) {
$data = json_decode($row['ii_info'], true);
} else {
// 외부 API 호출
$url = 'https://ipinfo.io/'.$ip.'/json?token=';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200 || !$response) {
return false;
}
$data = json_decode($response, true);
$escaped_response = addslashes($response);
$sql = "INSERT INTO typing_ipinfo
SET ii_ip = '".$ip."', ii_info = '".$escaped_response."', ii_datetime = '".G5_TIME_YMDHIS."'";
sql_query($sql, false);
}
if (!isset($data['region']) || !isset($data['city']) || !isset($data['loc'])) {
return "위치 정보 없음";
}
$region = htmlspecialchars($data['region'], ENT_QUOTES, 'UTF-8');
$city = htmlspecialchars($data['city'], ENT_QUOTES, 'UTF-8');
$loc = htmlspecialchars($data['loc'], ENT_QUOTES, 'UTF-8');
$str = $region . " " . $city . " ";
$str .= "<a href='https://maps.google.com/?q={$loc}&ll={$loc}&z=8' target='_blank'>(map)</a>";
return $str;
}
https://ipinfo.io

CREATE TABLE `typing_ipinfo` (
`ii_idx` int(11) NOT NULL AUTO_INCREMENT,
`ii_ip` varchar(45) NOT NULL,
`ii_info` text NOT NULL,
`ii_datetime` datetime NOT NULL,
PRIMARY KEY (`ii_idx`),
UNIQUE KEY `ii_ip` (`ii_ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
<?php echo get_ipinfo($row['ip']); ?>
[광고] 추억 속 타자 연습, 다시 시작해볼까요? - https://김타자.kr
댓글 2개
SQL 인젝션 취약점이 눈에 보입니다.
$sql = "SELECT * FROM typing_ipinfo WHERE ii_ip = '".$ip."'";
ip 값을 받아오는데 ' update ... admin 비번 변경 명령어 들어가면
관리자 아이디 비번 변경이 가능하니 패치를 하는걸 권장합니다.
예를 들면
if (empty($ip) || !filter_var($ip, FILTER_VALIDATE_IP)) {
return "유효하지 않은 IP 주소";
}
@카이루 감사합니다.
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5276 | 2년 전 | 1336 | |||
| 5275 | 2년 전 | 1406 | |||
| 5274 | 기타 | 2년 전 | 825 | ||
| 5273 | JavaScript |
swallow
|
2년 전 | 1056 | |
| 5272 | node.js |
swallow
|
2년 전 | 750 | |
| 5271 | JavaScript |
swallow
|
2년 전 | 1503 | |
| 5270 | PHP |
swallow
|
2년 전 | 850 | |
| 5269 | node.js |
swallow
|
2년 전 | 688 | |
| 5268 | node.js |
swallow
|
2년 전 | 1217 | |
| 5267 | PHP |
swallow
|
2년 전 | 1599 | |
| 5266 | MySQL |
swallow
|
2년 전 | 1096 | |
| 5265 | PHP |
swallow
|
2년 전 | 2036 | |
| 5264 | JavaScript |
swallow
|
2년 전 | 862 | |
| 5263 | 기타 |
swallow
|
2년 전 | 2985 | |
| 5262 | 기타 |
swallow
|
2년 전 | 671 | |
| 5261 | node.js |
swallow
|
2년 전 | 1066 | |
| 5260 | JavaScript |
swallow
|
2년 전 | 1514 | |
| 5259 | node.js |
swallow
|
2년 전 | 737 | |
| 5258 | node.js |
swallow
|
2년 전 | 1750 | |
| 5257 | node.js |
swallow
|
2년 전 | 1302 | |
| 5256 | PHP |
swallow
|
2년 전 | 1942 | |
| 5255 | node.js |
swallow
|
2년 전 | 692 | |
| 5254 | PHP |
swallow
|
2년 전 | 3018 | |
| 5253 | node.js |
swallow
|
2년 전 | 683 | |
| 5252 | 정규표현식 |
swallow
|
2년 전 | 625 | |
| 5251 | node.js |
swallow
|
2년 전 | 884 | |
| 5250 | PHP |
swallow
|
2년 전 | 1117 | |
| 5249 | node.js |
swallow
|
2년 전 | 1066 | |
| 5248 | PHP |
swallow
|
2년 전 | 1413 | |
| 5247 | node.js |
swallow
|
2년 전 | 1022 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기