외부 유입 검색어 분석기 채택완료
안녕하세요. 제 머리로는 해결이 않되서 또 질문을 들고 왔습니다.;;;
https://sir.kr/g4_skin/82558">외부 유입 검색어 분석기 - m3SearchQuery ver 1.21 > 그누4 스킨
위 파일은 그누보드4용 파일입니다.
방문자의 유입검색어를 보여주는 파일인데
이 파일을 그누보드 5로 바꿔서 사용하고 있습니다.
그런데 그누보드4에서는 유입검색어가 잘 나오는데
그누보드 5에서는 아무 것도 나오지 않습니다. ㅠ_ㅠ
그누보드4의 g4_visit의 구조는
http://sir.kr/data/editor/2509/31552942_1758720869.53.png" width="100%" />
위와 같으며 그누보드5의 g5_visit의 구조는 아래와 같습니다.
http://sir.kr/data/editor/2509/31552942_1758720931.4668.png" width="100%" />
g5_visit 테이블이 더 많아서 그누보드4용 파일을 5로 바꿔서 사용해도 될 것 같은데
왜 아무런 값도 출력되지 않는지 모르겠습니다.
아직 그누보드4로 운영되고 있는 사이트를 보면 잘 나오거든요.
http://sir.kr/data/editor/2509/31552942_1758721482.3775.png" width="100%" />
제가 사용한 파일은 원본에서
$g4[visit_table] 만 $g5['visit_table'] 로 수정해서 사용중입니다.
</p>
<p><?
$sub_menu = "200816";
include_once("./_common.php");
$g5['title'] ="검색어 분석기";
require_once './admin.head.php';
include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php');</p>
<p>// 날짜 설정
if(!$datefrom) $datefrom = date("Y-m-d", strtotime("1 days ago"));
if(!$dateto) $dateto = G5_TIME_YMD;</p>
<p>// 주사 지랄 방지
$datefrom = substr($datefrom, 0, 10);
$dateto = substr($dateto, 0, 10);
$site = substr($site, 0, 10);
$site_ori = $site;</p>
<p>// 검색사이트들
$site_arr = array("Google", "NAVER", "DAUM", "NATE", "Bing");
$surl_arr = array("Google" => "<a href="http://www.google.%"," target="_blank" rel="noopener noreferrer">http://www.google.%",</a> "NAVER" => "%search.naver.com%", "DAUM" => "%search.daum.net%", "NATE" => "%nate.com%", "Bing" => "<a href="http://www.bing.com%");" target="_blank" rel="noopener noreferrer">http://www.bing.com%");</a>
$svar_arr = array("Google" => "q", "NAVER" => "query", "DAUM" => "q", "NATE" => "q", "Bing" => "q");
?>
<style type="text/css">
#m3tbl { border:solid 1px #CCC; border-collapse:collapse;}
#m3tbl th { border:solid 1px #CCC; text-align:center;}
#m3tbl td { border:solid 1px #CCC; text-align:center; padding:2px 8px;}
#div_m3sq ul { display:inline; padding:0; margin:0; }
#div_m3sq ul li { display:inline; padding:10px 30px; border:solid 1px #3ad1d6; background: #3cd4d9; }
#div_m3sq ul li a {color:#fff; text-decoration: none; font-weight: bold;}
#div_m3sq ul li a:hover {color:#007b81; text-decoration: none; font-weight: bold;}
</style></p>
<p>
<div id="div_m3sq"></p>
<p>외부 유입 검색어 분석기
<ul>
<li><a href="<?php echo $PHP_SELF?>?dateto=<?php echo $dateto?>&datefrom=<?php echo $datefrom?>">All</a></li>
<? foreach($site_arr as $site) { ?>
<li><a href="<?php echo $PHP_SELF?>?site=<?php echo $site?>&dateto=<?php echo $dateto?>&datefrom=<?php echo $datefrom?>"><?php echo $site?></a></li>
<? } ?>
</ul></p>
<p>
</p>
<p><form action="<?php echo $_SERVER['PHP_SELF']?>" class="local_sch01 local_sch" method="get" style="overflow: hidden;">
<input type="hidden" name="site" value="<?php echo $site_ori?>" />
<div class="sch_last">
<strong>기간별검색</strong>
<input type="text" name="datefrom" id="datefrom" value="<?php echo $datefrom?>" class="frm_input" size="10" />
<label for="datefrom" class="sound_only">시작일</label>
~
<input type="text" name="dateto" id="dateto" value="<?php echo $dateto?>" class="frm_input" size="10" />
<label for="dateto" class="sound_only">종료일</label>
<input type="submit" value="검색" class="btn_submit" style=" background:#f8d034; font-weight:700; font-size:14px;width:80px; padding:10px;">
</div>
</form></p>
<p><script>
$(function(){
$("#datefrom, #dateto").datepicker({ changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd", showButtonPanel: true, yearRange: "c-99:c+99", maxDate: "+0d" });
});
</script></p>
<p><form action="javascript:;" onsubmit="findsq(getElementById('sq').value)" class="local_sch03 local_sch" style="overflow: hidden"/>
결과내 검색 : <input type="text" id="sq" name="sq" value="<?php echo $sq?>" class="frm_input" />
<input type="submit" value="검색" class="btn_submit" style=" background:#a2de14; font-weight:700; width:80px; padding:10px; border-radius:4px; font-size:14px;"/>
<input type="button" value="재설정" onclick="resetsq()" class="btn_submit" style=" background:#a2de14; font-weight:700; width:80px; padding:10px; border-radius:4px; font-size:14px;" />
<span id="search_cnt"></span>
</form>
</p>
<p><?
function get_os($agent)
{
$agent = strtolower($agent);</p>
<p> //echo $agent; echo "
";</p>
<p> if (preg_match("/windows 98/", $agent)) { $s = "98"; }
else if(preg_match("/windows 95/", $agent)) { $s = "95"; }
else if(preg_match("/windows nt 4\.[0-9]*/", $agent)) { $s = "NT"; }
else if(preg_match("/windows nt 5\.0/", $agent)) { $s = "2000"; }
else if(preg_match("/windows nt 5\.1/", $agent)) { $s = "XP"; }
else if(preg_match("/windows nt 5\.2/", $agent)) { $s = "2003"; }
else if(preg_match("/windows nt 6\.0/", $agent)) { $s = "Vista"; }
else if(preg_match("/windows nt 6\.1/", $agent)) { $s = "윈도우"; }
else if(preg_match("/windows 9x/", $agent)) { $s = "ME"; }
else if(preg_match("/windows ce/", $agent)) { $s = "CE"; }
else if(preg_match("/mac/", $agent) &&
preg_match("/iphone/", $agent)) { $s = "아이폰"; }
else if(preg_match("/mac/", $agent)) { $s = "맥"; }
else if(preg_match("/linux/", $agent) &&
preg_match("/android/", $agent)) { $s = "안드로이드"; }
else if(preg_match("/linux/", $agent)) { $s = "Linux"; }
else if(preg_match("/sunos/", $agent)) { $s = "sunOS"; }
else if(preg_match("/irix/", $agent)) { $s = "IRIX"; }
else if(preg_match("/phone/", $agent)) { $s = "Phone"; }
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
else if(preg_match("/mozilla/", $agent)) { $s = "크롬"; }
else { $s = "기타"; }</p>
<p> return $s;
}
// vi_referer에서 사이트 찾고, vi_date로 범위 정하기, 정렬은 vi_id 역순 (속도 개선 필요)
if(in_array($site_ori, $site_arr)) {
$where1 = "vi_referer LIKE '{$surl_arr[$site_ori]}' ";
}
else { // 5개 사이트 모두 포함
$where1 = " ( ";
foreach($surl_arr as $site => $surl) {
$where1 .= " vi_referer LIKE '$surl' OR ";
}
$where1 .= " 0 )";
}</p>
<p>// $query = sql_query("select * from `$g5[visit_table]` where $where1 AND vi_date>='$datefrom' AND vi_date<='$dateto' order by vi_id desc");</p>
<p>$sql = " select * from {$g5['visit_table']} where $where1 AND vi_date>='$datefrom' AND vi_date<='$dateto' ";
$sql .= " order by vi_id desc ";
// $sql .= " limit 0,101 ";
$query= sql_query($sql);</p>
<p>?>
<div class="tbl_head01 tbl_wrap" style="display: inline-block; width:100%;">
<table>
<caption><?php echo $g5['title']; ?> 목록</caption>
<thead>
<tr>
<th scope="col">날짜</th>
<th scope="col">사이트</th>
<th scope="col">검색어</th>
<th scope="col">IP</th>
<th scope="col">AGENT</th>
</tr>
</thead>
<tbody></p>
<p><?
$cnt = 0;
$cnt2 = array();</p>
<p>while($row = sql_fetch_array($query)) {
// 어느 사이트인지 찾기
foreach($surl_arr as $site => $surl) {
if(strstr($row['vi_referer'], str_replace("%", "", $surl))) {
$engine = $site;
break;
}
}
// 검색문자열 찾기
$regex = "/(\?|&){$svar_arr[$engine]}\=([^&]*)/i";
preg_match($regex, $row['vi_referer'], $matches);
$querystr = $matches[2];
// 보통 검색어 사이를 +로 넘긴다
$querystr = str_replace("+", " ", $querystr);
// %ab 이런 식으로 된 걸 바꿔주기
$querystr = urldecode($querystr);
// 네이버는 unicode로 된 경우도 있어서
if($engine=="Naver") $querystr = utf8_urldecode($querystr);
// 캐릭터셋이 EUC-KR인 경우는 UTF-8로 고치기 (EUC-KR 유저는 UTF-8과 EUC-KR를 서로 바꿔주면 될 듯)
$charset = mb_detect_encoding($querystr, "ASCII, UTF-8, EUC-KR");
if($charset=="EUC-KR") $querystr = iconv("EUC-KR", "UTF-8", $querystr);
// 자잘한 처리들
$querystr = trim($querystr);
$querystr = htmlspecialchars($querystr);
// 가끔 빈 것들도 있다 -_-
if(!strlen($querystr)) continue;
if($row['vi_ip'] == "124.111.187.193") { $row['vi_ip'] = "내부아이피"; }
// 에코
echo "<tr><td style='width:320px;'>".$row['vi_date']." ".$row['vi_time']."</td>";
echo "<td style='width:80px;'><a href=\"$PHP_SELF?site=$engine\"><img src=\"/adm/img/".strtolower($engine).".jpg\" /></a></td>";
echo "<td style=\"text-align:left\" id=\"m3sqtd[$cnt]\"><a href=\"$row[vi_referer]\" target=\"_blank\">$querystr</a></td>";
echo "<td style=\"text-align:left; width:120px;\">".$row['vi_ip']."</td>";
echo "<td style=\"text-align:left; width:120px;\">".get_os($row['vi_agent'])."</td></tr>\n";
// 카운트용 변수
$cnt++;
$cnt2[$engine]++;
}
ksort($cnt2);</p>
<p>// 베짱이님 제공 함수
function utf8_urldecode($str, $chr_set='CP949') {
$callback_function = create_function('$matches, $chr_set="'.$chr_set.'"', 'return iconv("UTF-16BE", $chr_set, pack("n*", hexdec($matches[1])));');
return rawurldecode(preg_replace_callback('/%u([[:alnum:]]{4})/', $callback_function, $str));
} </p>
<p>?>
</tbody>
</table>
</div>
Total : <?php echo $days=(strtotime($dateto)-strtotime($datefrom))/(24*60*60)+1?> days, <?php echo $cnt?> results (<?=sprintf("%.1f",$cnt/$days)?>/day)
<? if(!$site_ori) { // 모든 사이트의 경우 비율 분석
foreach($cnt2 as $engine => $count) {
echo "$engine : $count (".sprintf("%.1f",$count/$cnt*100)."%)
";
}
}?></p>
<p></div></p>
<p><script type="text/javascript">
function findsq(sq) {
if(sq=="") return;
var i = 0;
var search_cnt = 0; // 결과내 검색 개수
while(a = document.getElementById("m3sqtd["+i+"]")) {
if(a.innerText.toLowerCase().match(sq.toLowerCase())) { // 찾는 값이 있으면 보이기
a.parentNode.style.display="";
search_cnt++;
} else { // 찾는 값이 없으면 숨기기
a.parentNode.style.display="none";
}
i++;
}
document.getElementById("search_cnt").innerText = "결과내 검색 : " + search_cnt + "건";
}
function resetsq() {
var i = 0;
while(a = document.getElementById("m3sqtd["+i+"]")) {
a.parentNode.style.display=""; // 모든 행의 display 속성 reset
i++;
}
document.getElementById("search_cnt").innerText = "";
document.getElementById("sq").value = "";
}
</script>
<?php
include_once('./admin.tail.php');
?></p>
<p>
어디가 잘못된 것일까요?
고수님들 도와주세요. (/^^)/
답변 2개
![]()
제가 사용 중인 코드 입니다.
</p>
<p><?php
$sub_menu = "999920";
include_once('./_common.php');</p>
<p>auth_check($auth[$sub_menu], "r");</p>
<p>$g5['title'] = "외부 유입 검색어";
include_once(G5_ADMIN_PATH.'/admin.head.php');
include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php');
add_javascript('<script src="<a href="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>'," target="_blank" rel="noopener noreferrer">https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>',</a> 10);</p>
<p>$colspan = 6;</p>
<p>$day = 1; // 기본 검색 기간</p>
<p>if (empty($fr_date) || !preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $fr_date)) {
$fr_date = date("Y-m-d", strtotime($day . " days ago"));
}
if (empty($to_date) || !preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $to_date)) {
$to_date = G5_TIME_YMD;
}</p>
<p>$qstr = "fr_date=" . $fr_date . "&to_date=" . $to_date;
$query_string = $qstr ? '?' . $qstr : '';</p>
<p>$days = (strtotime($to_date) - strtotime($fr_date)) / (24 * 60 * 60) + 1;</p>
<p>$site = substr(isset($site), 0, 10);
$site_ori = $site;</p>
<p>$site_arr = ["Naver", "Google", "Nate", "Yahoo", "Daum", "Bing"];
$surl_arr = [
"Naver" => "%naver.com%",
"Google" => "<a href="http://www.google.%"," target="_blank" rel="noopener noreferrer">http://www.google.%",</a>
"Nate" => "%nate.com%",
"Yahoo" => "%search.yahoo.com%",
"Daum" => "%search.daum.net%",
"Bing" => "<a href="http://www.bing.com%"" target="_blank" rel="noopener noreferrer">http://www.bing.com%"</a>
];
$svar_arr = [
"Naver" => "query",
"Google" => "q",
"Nate" => "q",
"Yahoo" => "p",
"Daum" => "q",
"Bing" => "q"
];</p>
<p>$listall = '<a href="' . $_SERVER['SCRIPT_NAME'] . '" class="ov_listall">전체목록</a>';</p>
<p>$sql_common = " FROM {$g5['visit_table']} ";
$sql_search = " WHERE vi_date BETWEEN '{$fr_date}' AND '{$to_date}' ";</p>
<p>if ($stx) {
$stx = str_replace(["\"", "\'"], "", $stx);
$sql_search .= " AND vi_ip = '{$stx}'";
}</p>
<p>if (isset($st) && trim($sv)) {
$sql_search .= " AND vi_ip LIKE '%$sv%'";
}</p>
<p>if (isset($site)) {
if (in_array($site_ori, $site_arr)) {
$sql_search .= " AND vi_referer LIKE '{$surl_arr[$site_ori]}'";
} else {
$sql_search .= " AND (";
foreach ($surl_arr as $site => $surl) {
$sql_search .= " vi_referer LIKE '$surl' OR ";
}
$sql_search .= " 0 )";
}
}</p>
<p>$sql = "SELECT * {$sql_common} {$sql_search} ORDER BY vi_id DESC";
$result = sql_query($sql);</p>
<p>$total_count = 0;
$cnt2 = array_fill_keys($site_arr, 0);
$rows = [];</p>
<p>while ($row = sql_fetch_array($result)) {
$engine = '';
foreach ($surl_arr as $site => $surl) {
if (strstr($row['vi_referer'], str_replace("%", "", $surl))) {
$engine = $site;
break;
}
}</p>
<p> $querystr = '';
if (array_key_exists($engine, $svar_arr)) {
$regex = "/(\?|&){$svar_arr[$engine]}=([^&]*)/i";
preg_match($regex, $row['vi_referer'], $matches);
if (isset($matches[2])) {
$querystr = urldecode(str_replace("+", " ", $matches[2]));
if ($engine == "Naver") {
$querystr = utf8_urldecode($querystr);
}
$charset = mb_detect_encoding($querystr, "ASCII, euc-KR, utf-8");
if ($charset == "euc-kr") {
$querystr = iconv("euc-kr", "utf-8", $querystr);
}
$querystr = trim(htmlspecialchars($querystr));
}
}</p>
<p> if (strlen($querystr)) {
$rows[] = [
'vi_date' => $row['vi_date'],
'vi_time' => $row['vi_time'],
'engine' => $engine,
'vi_referer' => $row['vi_referer'],
'querystr' => $querystr,
'vi_device' => $row['vi_device'],
'vi_ip' => $row['vi_ip']
];
$total_count++;
$cnt2[$engine]++;
}
}</p>
<p>function utf8_urldecode($str, $chr_set = 'CP949') {
$callback_function = function ($matches) use ($chr_set) {
return iconv("UTF-16BE", $chr_set, pack("n*", hexdec($matches[1])));
};
return rawurldecode(preg_replace_callback('/%u([[:alnum:]]{4})/', $callback_function, $str));
}
?></p>
<p><div class="local_ov01 local_ov">
<?php echo $listall ?>
<span class="btn_ov01"><span class="ov_txt">전체 </span><span class="ov_num"> <?php echo number_format($total_count) ?> 건 </span></span>
<span class="btn_ov01"><span class="ov_txt">1일 평균</span><span class="ov_num"><?php echo sprintf("%.1f", $total_count / $days) ?> 건 </span></span>
<?php
if (!$site_ori) {
foreach ($cnt2 as $engine => $count) {
// $total_count가 0이면 나누기 오류 발생하므로 방지
if (!isset($total_count) || $total_count == 0) {
$percentage = 0;
} else {
$percentage = sprintf("%.1f", $count / $total_count * 100);
}
echo ' <span class="btn_ov01"><span class="ov_txt">' . htmlspecialchars($engine, ENT_QUOTES, 'UTF-8') . '</span>';
echo '<span class="ov_num">' . $count . ' 건 (' . $percentage . '%) </span></span>';
}
}
?>
</div></p>
<p><form name="fvisit" id="fvisit" class="local_sch03 local_sch" method="get">
<div class="sch_last">
<strong>기간별검색</strong>
<input type="text" name="fr_date" value="<?php echo $fr_date ?>" id="fr_date" class="frm_input" size="11" maxlength="10">
<label for="fr_date" class="sound_only">시작일</label>
~
<input type="text" name="to_date" value="<?php echo $to_date ?>" id="to_date" class="frm_input" size="11" maxlength="10">
<label for="to_date" class="sound_only">종료일</label>
<input type="submit" value="검색" class="btn_submit">
</div>
</form></p>
<p><form name="search_form" id="search_form" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" class="local_sch01 local_sch" method="get">
<label for="st" class="sound_only">검색대상</label>
<input type="hidden" name="st" id="st" value="vi_ip">
<label for="sv" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="sv" value="<?php echo isset($sv) ?>" id="sv" required class="required frm_input" placeholder="IP 검색">
<input type="submit" value="검색" class="btn_submit">
</form></p>
<p><ul class="anchor">
<li><a href="<?php echo $PHP_SELF; ?><?php echo $query_string ?>">All</a></li>
<?php foreach ($site_arr as $site) { ?>
<li><a href="<?php echo $PHP_SELF; ?><?php echo $query_string ?>&site=<?php echo $site; ?>"><?php echo $site; ?></a></li>
<?php } ?>
</ul></p>
<p><?php if ($stx) { ?>
<div class="btn_list03 btn_list">
<a href="<?php echo $_SERVER['PHP_SELF'] ?><?php echo $query_string ?>">IP 필터 풀기</a>
</div>
<?php } ?></p>
<p><script>
$(function() {
$("#fr_date, #to_date").datepicker({ changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd", showButtonPanel: true, yearRange: "c-99:c+99", maxDate: "+0d" });
});</p>
<p>function fvisit_submit(act) {
var f = document.fvisit;
f.action = act;
f.submit();
}
</script></p>
<p><div class="tbl_head01 tbl_wrap">
<table>
<caption><?php echo $g5['title']; ?> 목록</caption>
<thead>
<tr>
<th scope="col">날짜</th>
<th scope="col">시간</th>
<th scope="col">사이트</th>
<th scope="col">검색어</th>
<th scope="col">접속기기</th>
<th scope="col">IP</th>
</tr>
</thead>
<tbody>
<?php if (!empty($rows)) { ?>
<?php foreach ($rows as $i => $r) { ?>
<tr class="bg<?php echo $i % 2; ?>">
<td class="td_datetime"><?php echo $r['vi_date']; ?></td>
<td class="td_datetime"><?php echo $r['vi_time']; ?></td>
<td class="td_category"><img src="./img/<?php echo strtolower($r['engine']); ?>.jpg" alt="<?php echo $r['engine']; ?>"></td>
<td><a href="<?php echo $r['vi_referer']; ?>" target="_blank"><?php echo $r['querystr']; ?></a></td>
<td class="td_category td_category2"><?php echo $r['vi_device']; ?></td>
<td class="td_category td_category2"><a href="<?php echo $_SERVER['PHP_SELF'] . $query_string . '&stx=' . $r['vi_ip']; ?>"><?php echo $r['vi_ip']; ?></a></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6" class="empty_table">검색 결과가 없습니다.</td>
</tr>
<?php } ?>
</tbody>
</table>
</div></p>
<p><?php
include_once G5_ADMIN_PATH . "/admin.tail.php";</p>
<p>
답변에 대한 댓글 3개
올려주신 소스로 적용해보았는데도, 검색결과가 전혀 나오지 않습니다.
(접속자 집계 페이지에서 보면 오늘오전에만 네이버를 통해 30명 이상이 유입됐습니다.)
왜 그럴까요? ㅠㅠ
결과는 바로 보이지 않고 시간이 지나야 나옵니다.
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 3개
네이버가 리퍼러를 막았는지는 모르곘는데. g4로 만들어진 사이트에서는
오늘도 여전히 유입 검색어가 잘 나옵니다.
위에 그누보드4로 운영되고 있는 사이트의 검색어를 보시면 오늘날짜부터 잘 나오고 있습니다.
https://sir.kr/g5_plugin/4635
이거저거 다 적용해보면 잘 되는거 하나는 있겠네요 ^^
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
적용해서 사용해 보겠습니다.