-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter_app.php
227 lines (204 loc) · 8.09 KB
/
counter_app.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?
//$Dir="../";
//include_once($Dir."lib/init.php");
//include_once($Dir."lib/lib.php");
function getUnescape($str){
return urldecode(preg_replace_callback('/%u([[:alnum:]]{4})/', 'UnescapeFunc', $str));
}
function UnescapeFunc($str){
return mb_convert_encoding(chr(hexdec(substr($str[1], 2, 2))).chr(hexdec(substr($str[1],0,2))),"UHC","UTF-16LE");
}
$ref=$_REQUEST["ref"];
$url=$_ShopInfo->getShopurl();
/*
if(strlen(getenv("HTTP_REFERER"))==0) {
echo "사이트에 링크하셔야 나옵니다.";
exit;
}
*/
$cookie_set = $_COOKIE["shop_counter"];
$cookie_set_N = $_COOKIE["shop_counter_N"];
$N_date = date("Ymd");
$date = date("YmdH");
$date2 = substr($date,0,8);
$date3 = substr($date,0,6);
echo $cookie_set;
//1일 접속자
if (!$cookie_set) {
//금일 확인
//tblcontact_ip
//금일 이전 자료는 삭제
$sql_del = "DELETE FROM tblcontact_ip WHERE date != '".$N_date."' ";
mysql_query($sql_del,get_db_conn());
//금일 자료 업데이트
$ip_k = $_SERVER['REMOTE_ADDR'];
$sql_ip = "SELECT count(*) as cnt FROM tblcontact_ip WHERE date = '".$N_date."' and ip = '".$ip_k."' ";
$result_ip = mysql_query($sql_ip,get_db_conn());
if($row_ip = mysql_fetch_object($result_ip)) {
$ip_cnt = (int)$row_ip->cnt;
}
if($ip_cnt == 0){
//IP 추가
mysql_query("INSERT INTO tblcontact_ip (date,ip) VALUES ('".$N_date."', '".$ip_k."')",get_db_conn());
//INSERT or UPDATE
//tblcounter_contact
$sql_date = "SELECT count(*) as cnt FROM tblcounter_contact WHERE date = '".$N_date."' ";
$result_date = mysql_query($sql_date,get_db_conn());
if($row_date = mysql_fetch_object($result_date)) {
$date_cnt = (int)$row_date->cnt;
}
if($date_cnt == 0){
mysql_query("INSERT INTO tblcounter_contact (date,cnt) VALUES ('".$N_date."',1)",get_db_conn());
}else{
mysql_query("UPDATE tblcounter_contact SET cnt=cnt+1 WHERE date='".$N_date."' ",get_db_conn());
}
//쿠키추가
setcookie("shop_counter_N",$N_date,0,"/".RootPath);
}
}
//1일 접속자
mysql_query("INSERT INTO tblcounter (date,pagecnt) VALUES ('".$date."',1)",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounter SET pagecnt=pagecnt+1 WHERE date='".$date."' ",get_db_conn());
}
if ($cookie_set != $date) {
// 시간별 카운트
mysql_query("INSERT INTO tblcounter (date,pagecnt) VALUES ('".$date."',1)",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounter SET cnt=cnt+1 WHERE date='".$date."' ",get_db_conn());
}
setcookie("shop_counter",$date,0,"/".RootPath);
}
// 페이지뷰 설정
$page = ereg_replace("http://","",getenv("HTTP_REFERER"));
if (strpos($page,"/")!=0) {
$pageurl = substr($page,0,strpos($page,"/"));
$pageview = substr($page,strpos($page,"/")+1);
// 상품코드 추출
if (strpos($page,"productdetail.php")>0 && strpos($pageview,"productcode=")>0) {
$shopdetail = $pageview;
$pos = strpos($shopdetail,"productcode=")+12;
$productcode = substr($shopdetail,$pos,18);
if (strlen($productcode)>12) {
mysql_query("INSERT INTO tblcounterproduct (date,productcode) VALUES ('".$date2."','".$productcode."')",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounterproduct SET cnt=cnt+1 WHERE date='".$date2."' AND productcode='".$productcode."'",get_db_conn());
}
}
} else if (strpos($page,"productlist.php")>0 && strpos($pageview,"code=")>0) {
$codelink = $pageview;
$pos = strpos($codelink,"code=")+5;
$str = substr($codelink,$pos,12);
$code="";
for($i=0;$i<strlen($str);$i++){
if("0"<=$str[$i] && $str[$i]<="9") $code.=$str[$i];
}
if (strlen($code)==3 || strlen($code)==12) {
if(strlen($code)==3) $code.="000000000";
mysql_query("INSERT INTO tblcountercode (date,code) VALUES ('".$date2."','".$code."')",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcountercode SET cnt=cnt+1 WHERE date='".$date2."' AND code='".$code."' ",get_db_conn());
}
}
} else if (strpos($page,"productsearch.php")>0 && strpos($pageview,"search=")>0) {
//검색어
$shopdetail = $pageview;
$pos = strpos($shopdetail,"search=")+7;
if ($pos>7) {
$shopdetail = substr($shopdetail,$pos);
if(strpos($shopdetail,"&")!=false) {
$pos = strpos($shopdetail,"&");
$search = substr($shopdetail,0,$pos);
} else {
$search = $shopdetail;
}
if (strlen($search)>0) {
$search=urldecode($search);
mysql_query("INSERT INTO tblcounterkeyword (date,search) VALUES ('".$date2."','".$search."')",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounterkeyword SET cnt=cnt+1 WHERE date='".$date2."' AND search='".$search."'",get_db_conn());
}
}
}
}
if (strpos($pageview,"?")!=false) $pageview = substr($pageview,0,strpos($pageview,"?"));
}
// 페이지뷰체크
if (strlen($pageview)>0) {
mysql_query("INSERT INTO tblcounterpageview (date,page) VALUES ('".$date2."','".$pageview."')",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounterpageview SET cnt=cnt+1 WHERE date='".$date2."' AND page='".$pageview."'",get_db_conn());
}
// 주문체크
if (strpos($pageview,"orderend.php")>0) {
mysql_query("INSERT INTO tblcounterorder (date) VALUES ('".$date."')",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounterorder SET cnt=cnt+1 WHERE date='".$date."'",get_db_conn());
}
}
}
// 링크URL체크
if (strlen(trim($ref))>0 && strpos($ref,$url)===false) {
$ref = preg_replace('!^(http[s]?://)!','',$ref);
$searchword = preg_replace('!^(http[s]?://)!','',$searchword);
if (strpos($ref,"/")!=0) $ref = substr($ref,0,strpos($ref,"/"));
$result = mysql_query("SELECT COUNT(*) as cnt FROM tblcountersearchdomain WHERE domain='".$ref."'",get_db_conn());
$row=mysql_fetch_object($result);
$cnt = $row->cnt;
mysql_free_result($result);
// 검색엔진사이트일경우
if ($cnt==1) {
mysql_query("INSERT INTO tblcountersearchengine (date,domain) VALUES ('".$date2."','".$ref."') ",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcountersearchengine SET cnt=cnt+1 WHERE date='".$date2."' AND domain='".$ref."'",get_db_conn());
}
switch ($ref) {
case "kr.search.yahoo.com":
$searchquery="p=";
break;
case "search.naver.com":
case "web.search.naver.com":
case "searchplus.nate.com":
case "search.nate.com":
case "search.hanafos.com":
$searchquery="query=";
break;
case "search.korea.com":
case "search.freechal.com":
$searchquery="query=";
break;
case "search.paran.com":
$searchquery="Query=";
break;
default :
$searchquery="q=";
break;
}
if (strpos($searchword,$searchquery)>0) {
//if (($ref=="www.google.co.kr" && strpos($searchword,"UTF-8")>0) || ($ref=="search.msn.co.kr" && strpos($searchword,"MSNH")<=0)){
if ($ref=="www.google.co.kr" || ($ref=="search.msn.co.kr" && strpos($searchword,"MSNH")<=0) || ($ref=="search.daum.net" && strpos($searchword,"utf8")>0) || ($ref=="kr.search.yahoo.com" && strpos($searchword,"kr-search_top")>0)){
$searchword=@mb_convert_encoding(urldecode($searchword),"utf-8","auto");
}
$searchword = trim(urldecode(substr($searchword,strpos($searchword,$searchquery)+strlen($searchquery))));
if (strpos($searchword,"&")>0) $searchword = substr($searchword,0,strpos($searchword,"&"));
if (strlen($searchword)>0) {
if($ref=="search.naver.com" || $ref=="web.search.naver.com") {
$searchword = getUnescape($searchword);
}
mysql_query("INSERT INTO tblcountersearchword (date,domain,search) VALUES ('".$date3."','".$ref."','".$searchword."') ",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcountersearchword SET cnt=cnt+1 WHERE date='".$date3."' AND domain='".$ref."' AND search='".$searchword."'",get_db_conn());
}
}
}
} else {
mysql_query("INSERT INTO tblcounterdomain (date,domain) VALUES ('".$date2."','".$ref."') ",get_db_conn());
if (mysql_errno()==1062) {
mysql_query("UPDATE tblcounterdomain SET cnt=cnt+1 WHERE date='".$date2."' AND domain='".$ref."'",get_db_conn());
}
}
}
//header("Content-type: image/gif");
$array = array(71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
//foreach ($array as $asc) echo chr($asc);
?>