
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개
게시글 목록
| 번호 | 제목 |
|---|---|
| 18200 | |
| 18195 | |
| 18193 | |
| 18181 | |
| 18179 | |
| 18173 | |
| 18170 | |
| 18164 | |
| 18158 | |
| 18155 | |
| 18152 |
JavaScript
한글과컴퓨터 키워드추출스크립트.
2
|
| 18151 | |
| 18150 |
JavaScript
위에서 아래로 내려오는 효과 6가지
|
| 18140 | |
| 18139 | |
| 18138 |
JavaScript
마우스로 td 간격 조정하기.
1
|
| 18131 | |
| 18130 |
JavaScript
엘레먼트에 다이렉트로 변수,배열,객체 심기
|
| 18120 | |
| 18119 | |
| 18118 |
jQuery
0원팁- 숫자형 아이디에 접근하기
1
|
| 18117 |
jQuery
유용하게 써먹는 반응형 grid
1
|
| 18116 | |
| 18111 |
MySQL
db에서 트리거 만들기
|
| 18110 | |
| 18108 |
JavaScript
디바운스 debounce의 개념
1
|
| 18107 |
JavaScript
jquery 타이머 만들기
2
|
| 18106 | |
| 18100 | |
| 18090 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기