2026, 새로운 도약을 시작합니다.

접속자 집계 IP정보 조회 기능 추가

· 2개월 전 · 191

접속자 집계 정보 추가하는 방법 공유합니다.

둘레아빠님 소스 포함했습니다.

3732210772_1760275961.5211.gif

IP를 클릭하면 팝업으로 상세하게 확인가능합니다.

adm/visit_list.php

[code]

<?php
$sub_menu = "200800";
include_once('./_common.php');

auth_check_menu($auth, $sub_menu, 'r');

$fr_date = isset($_REQUEST['fr_date']) ? preg_replace('/[^0-9 :\-]/i', '', $_REQUEST['fr_date']) : G5_TIME_YMD;
$to_date = isset($_REQUEST['to_date']) ? preg_replace('/[^0-9 :\-]/i', '', $_REQUEST['to_date']) : G5_TIME_YMD;

$g5['title'] = '접속자집계';
include_once('./visit.sub.php');

$colspan = 6;

$sql_common = " from {$g5['visit_table']} ";
$sql_search = " where vi_date between '{$fr_date}' and '{$to_date}' ";
if (isset($domain))
    $sql_search .= " and vi_referer like '%{$domain}%' ";

$sql = " select count(*) as cnt
            {$sql_common}
            {$sql_search} ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];

$rows = $config['cf_page_rows'];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page < 1) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$sql = " select *
            {$sql_common}
            {$sql_search}
            order by vi_id desc
            limit {$from_record}, {$rows} ";
$result = sql_query($sql);
?>

<div class="tbl_head01 tbl_wrap">
    <table>
    <caption><?php echo $g5['title']; ?> 목록</caption>
    <thead>
    <tr>
        <th scope="col">IP</th>

<!-- 추가 부분 시작 -->
        <th scope="col">접속 국가</th>

<!-- 추가 부분 끝 -->
        <th scope="col">접속 경로</th>
        <th scope="col">브라우저</th>
        <th scope="col">OS</th>
        <th scope="col">접속기기</th>
        <th scope="col">일시</th>
    </tr>
    </thead>
    <tbody>
    <?php
    for ($i=0; $row=sql_fetch_array($result); $i++) {
        $brow = $row['vi_browser'];
        if(!$brow)
            $brow = get_brow($row['vi_agent']);

        $os = $row['vi_os'];
        if(!$os)
            $os = get_os($row['vi_agent']);

        $device = $row['vi_device'];

        $link = '';
        $link2 = '';
        $referer = '';
        $title = '';
        if ($row['vi_referer']) {

            $referer = get_text(cut_str($row['vi_referer'], 255, ''));
            $referer = urldecode($referer);

            if (!is_utf8($referer)) {
                $referer = iconv_utf8($referer);
            }

            $title = str_replace(array('<', '>', '&'), array("&lt;", "&gt;", "&amp;"), $referer);
            $link = '<a href="'.get_text($row['vi_referer']).'" target="_blank">';
            $link = str_replace('&', "&amp;", $link);
            $link2 = '</a>';
        }

        if ($is_admin == 'super')
            $ip = $row['vi_ip'];
        else
            $ip = preg_replace("/([0-9]+).([0-9]+).([0-9]+).([0-9]+)/", G5_IP_DISPLAY, $row['vi_ip']);

        if ($brow == '기타') { $brow = '<span title="'.get_text($row['vi_agent']).'">'.$brow.'</span>'; }
        if ($os == '기타') { $os = '<span title="'.get_text($row['vi_agent']).'">'.$os.'</span>'; }

        $bg = 'bg'.($i%2);
    ?>
    <tr class="<?php echo $bg; ?>">

        <td class="td_category"><!-- 수정  및 추가 부분 시작 --><a href="#" class="ip-info" data-ip="<?php echo $ip;?>"><?php echo $ip ?></a>
            <div id="ipModal" style="display:none; position:fixed; top:20%; left:30%; width:40%; background:#fff; border:1px solid #ccc; padding:20px; z-index:9999;">
                <h3>IP 정보</h3>
                <div id="ipResult">불러오는 중...</div>
                <button onclick="document.getElementById('ipModal').style.display='none'">닫기</button>
            </div>

<!-- 수정  및 추가 끝-->
        </td>

<!-- 추가 부분 시작 -->
        <td><span class="crt_name"><?php $country = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));echo ' '.$country->country.' '.$country->city; ?></span></td>

<!-- 추가 부분 끝-->
        <td><?php echo $link ?><?php echo $title ?><?php echo $link2 ?></td>
        <td class="td_category td_category1"><?php echo $brow ?></td>
        <td class="td_category td_category3"><?php echo $os ?></td>
        <td class="td_category td_category2"><?php echo $device; ?></td>
        <td class="td_datetime"><?php echo $row['vi_date'] ?> <?php echo $row['vi_time'] ?></td>
    </tr>

    <?php
    }
    if ($i == 0)
        echo '<tr><td colspan="'.$colspan.'" class="empty_table">자료가 없거나 관리자에 의해 삭제되었습니다.</td></tr>';
    ?>
    </tbody>
    </table>
</div>

<!-- 추가 부분 시작 -->
<script>
document.addEventListener("DOMContentLoaded", function() {
    const ipLinks = document.querySelectorAll(".ip-info");
    ipLinks.forEach(link => {
        link.addEventListener("click", function(e) {
            e.preventDefault();
            const ip = this.dataset.ip;
            document.getElementById("ipModal").style.display = "block";
            document.getElementById("ipResult").innerHTML = "불러오는 중...";

            // PHP 코드 제거됨
            fetch("visit_ipinfo_ajax.php?ip=" + encodeURIComponent(ip))
                .then(response => response.text())
                .then(data => {
                    document.getElementById("ipResult").innerHTML = data;
                })
                .catch(error => {
                    document.getElementById("ipResult").innerHTML = "정보를 불러올 수 없습니다.";
                    console.error("Fetch error:", error);
                });
        });
    });
});
</script>

<!-- 추가 부분 끝-->
<?php
if (isset($domain))
    $qstr .= "&amp;domain=$domain";
$qstr .= "&amp;page=";

$pagelist = get_paging($config['cf_write_pages'], $page, $total_page, "{$_SERVER['SCRIPT_NAME']}?$qstr");
echo $pagelist;

include_once('./admin.tail.php');

[/code]

visit_ipinfo_ajax.php  //파일생성

[code]

<?php
$ip = $_GET['ip'] ?? '';
if (filter_var($ip, FILTER_VALIDATE_IP)) {
    $url = "https://ipinfo.io/{$ip}/json";
    $response = file_get_contents($url);
    if ($response !== false) {
        $data = json_decode($response, true);
        unset($data['readme']);


        echo "<ul>";
        foreach ($data as $key => $value) {
            echo "<li><strong>{$key}:</strong> {$value}</li>";
        }
        echo "</ul>";
    } else {
        echo "API 요청 실패.";
    }
} else {
    echo "유효한 IP 주소가 아닙니다.";
}
?>

[/code]

|

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,594
2711 2개월 전 조회 323
2710 2개월 전 조회 225
2709 2개월 전 조회 393
2708 2개월 전 조회 232
2707 2개월 전 조회 275
2706 2개월 전 조회 273
2705 2개월 전 조회 144
2704 2개월 전 조회 295
2703 2개월 전 조회 268
2702 2개월 전 조회 282
2701 2개월 전 조회 278
2700 2개월 전 조회 225
2699 2개월 전 조회 172
2698 2개월 전 조회 221
2697 2개월 전 조회 192
2696 2개월 전 조회 165
2695 3개월 전 조회 321
2694 3개월 전 조회 160
2693 3개월 전 조회 214
2692 3개월 전 조회 219
2691 3개월 전 조회 364
2690 3개월 전 조회 269
2689 3개월 전 조회 290
2688 3개월 전 조회 239
2687 3개월 전 조회 451
2686 3개월 전 조회 503
2685 3개월 전 조회 635
2684 3개월 전 조회 371
2683 3개월 전 조회 513
2682 3개월 전 조회 325
🐛 버그신고