/home/mjc1/public_html/come_ref.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
<?php
header
("Access-Control-Allow-Origin: *"); 
include(
"./common.php");
@
session_start();
print_r($_COOKIE);
print_r($_POST);
$post $_POST;

function 
get_random_string($type ''$len 10) {
    
$lowercase 'abcdefghijklmnopqrstuvwxyz';
    
$uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
$numeric '0123456789';
    
$special '`~!@#$%^&*()-_=+\|[{]};:\'",<.>/?';
    
$key '';
    
$token '';
    if (
$type == '') {
        
$key $lowercase.$uppercase.$numeric;
    } else {
        if (
strpos($type,'09') > -1$key .= $numeric;
        if (
strpos($type,'az') > -1$key .= $lowercase;
        if (
strpos($type,'AZ') > -1$key .= $uppercase;
        if (
strpos($type,'$') > -1$key .= $special;
    }
    for (
$i 0$i $len$i++) {
        
$token .= $key[mt_rand(0strlen($key) - 1)];
    }
    return 
$token;
}

$vv explode(";",$post['HTTP_COOKIE']);
foreach(
$vv as $k=>$v){
    
$v1 explode("=",$v);
    if(
trim($v1[0])=='USERID'){
        
$_COOKIE['USERID'] = trim($v1[1]);
        break;
    }
}

$do_insert "Y";

if(
$post['HTTP_USER_AGENT']=='' || $post['REMOTE_ADDR']=='' || $post['REMOTE_ADDR']==''){ // 정보 없는거 제거
    
$do_insert "N";
}

if(
strpos($post['HTTP_USER_AGENT'],"Yeti")>|| strpos($post['HTTP_USER_AGENT'],"http://naver.me/spd")>0){ // 네이버 봇 제거
    
$do_insert "N";
}

if(
strpos($post['HTTP_USER_AGENT'],"YandexBot")>0){ // ? 봇 제거
    
$do_insert "N";
}

if(
strpos($post['HTTP_USER_AGENT'],"Googlebot")>|| strpos($post['HTTP_USER_AGENT'],"adsbot")>|| strpos($post['HTTP_USER_AGENT'],"oogle-Ads-Overview")>|| strpos($post['HTTP_USER_AGENT'],"googlebot")>0){ // 구글 봇 제거
    
$do_insert "N";
}


/*$sql = "select idx, referer from visit_ref_log where sess_id = '{$_COOKIE['PHPSESSID']}' order by idx desc limit 1";
$res = mysql_query($sql,$connect_web);
$info = mysql_fetch_array($res);
if($info['referer']==$post['HTTP_REFERER']){
    $sql = "update visit_ref_log set clicks = clicks + 1 where idx = '{$info['idx']}' ";
} else {*/
if($do_insert=='Y'){
    if(
$_POST['session_key']!=''){
        
$_SESSION['ref_log_key'] = $_POST['session_key'];
    } else if(
$_SESSION['ref_log_key']==''){
        
$_SESSION['ref_log_key'] = get_random_string('azAZ09').get_microtime();
    }
    
$cur_date date("Y-m-d H:i:s",time());
    
$post['HTTP_REFERER'] = urldecode($post['HTTP_REFERER']);
    
$post['HTTP_REFERER'] = iconv("utf8","euckr",$post['HTTP_REFERER']);

    
$ref_key "";
    if(
strpos($post['HTTP_REFERER'],"query=")>0){
        
$v explode("query=",$post['HTTP_REFERER']);
        
$vv $v[1];
        
$v1 explode("&",$vv);
        
$ref_key $v1[0];
    }
    
$sql "insert into visit_ref_log set 
                sess_id = '
{$_COOKIE['PHPSESSID']}', referer = '{$post['HTTP_REFERER']}', user_agent = '{$post['HTTP_USER_AGENT']}', ip = '{$post['REMOTE_ADDR']}', 
                user_id = '
{$_COOKIE['USERID']}', scrtip_name = '{$post['SCRIPT_NAME']}', http_host = '{$post['HTTP_HOST']}', reg_date = '".$cur_date."', 
                session_key = '
{$_SESSION['ref_log_key']}', ref_key = '{$ref_key}', qstr = '{$post['QUERY_STRING']}'
    "
;
    
//_pr($sql);
    
mysql_query($sql,$connect_web);

    
// 같은 IP/같은 agent에서 5초 이전에 세션_id가 없고 세션키가 다른 로그에 대해서 세션키 보정처리 검색되어 올때나 mijinsoft.co.kr로 접근하면 도메인이나 세션키가 정상적으로 안되므로 그부분 보정위함
    
$idx mysql_insert_id($connect_web);
    
$sql "select * from visit_ref_log a 
                where a.ip = '
{$post['REMOTE_ADDR']}' and sess_id = '' 
                and user_agent = '
{$post['HTTP_USER_AGENT']}
                and idx <> '
{$idx}' order by idx desc limit 1
    "
;
    
$res mysql_query($sql,$connect_web);
    
$info mysql_fetch_array($res);
    
$secon_3b strtotime("-5 second {$cur_date}");
    
$k_date date("Y-m-d H:i:s",$secon_3b);
    if(
$info['session_key']!=$_SESSION['ref_log_key'] && $k_date<=$info['reg_date']){
        
$sql "update visit_ref_log set session_key = '{$_SESSION['ref_log_key']}' where idx = '{$info['idx']}' ";
        
mysql_query($sql,$connect_web);
    }
}
//}

echo $do_insert;
?>