Exemplo n.º 1
0
function targets_matched($targets, $browser_save, $is_detail = false)
{
    $matched = false;
    if (empty($targets)) {
        omp_trace('targets empty.');
        return $matched;
    }
    foreach ($targets as $target) {
        do {
            $key_names = ['ismobiledevice', 'browser', 'platform', 'device_name', 'region'];
            if (!match_normal($target, $browser_save, $key_names)) {
                omp_trace('browser matched failure');
                break;
            }
            //正则表达式匹配UA,如果不匹配则这条任务略过
            $UA = $browser_save['UserAgent'] . $browser_save['XRequestWith'];
            if (!match_regex($UA, $target['UserAgent'])) {
                omp_trace('UserAgent substr: ' . $UA . '!=' . $target['UserAgent']);
                break;
            }
            //如果是详细匹配,要包括实时的Visiting和Account
            if ($is_detail) {
                $key_names = ['new_user', 'new_visitor', 'binded', 'bind_account'];
                if (!match_normal($target, $browser_save, $key_names)) {
                    omp_trace('user matched failure');
                    break;
                }
                //正访问网址的正则匹配
                if (!match_regex($browser_save['Visiting'], $target['Visiting'])) {
                    omp_trace('target : ' . $browser_save['Visiting'] . '!=' . $target['Visiting']);
                    break;
                }
                //访问停留时间
                if (!match_range($browser_save['sec_staytime'], $target['stay_time'])) {
                    omp_trace('target sec_staytime: ' . $browser_save['sec_staytime'] . '!=' . $target['stay_time']);
                    break;
                }
                //访问页面次数
                if (!match_range($browser_save['sec_pageviews'], $target['pageview_range'])) {
                    omp_trace('target sec_pageviews: ' . $browser_save['sec_pageviews'] . '!=' . $target['pageview_range']);
                    break;
                }
                //总访问页面次数
                if (!match_range($browser_save['all_pageviews'], $target['allpageview_range'])) {
                    omp_trace('target all_pageviews: ' . $browser_save['all_pageviews'] . '!=' . $target['allpageview_range']);
                    break;
                }
                //来访次数
                if (!match_range($browser_save['visit_times'], $target['visit_times_range'])) {
                    omp_trace('target visit_times: ' . $browser_save['visit_times'] . '!=' . $target['visit_times_range']);
                    break;
                }
            }
            //过关斩将,最后匹配成功了
            $matched = $target;
            omp_trace('match: ' . $target['name']);
            break 2;
        } while (false);
    }
    return $matched;
}
Exemplo n.º 2
0
function targets_matched($targets, $browser_save, $is_detail = false)
{
    $matched = false;
    if (empty($targets)) {
        omp_trace('targets empty.');
        return true;
    }
    foreach ($targets as $target) {
        do {
            $key_names = ['ismobiledevice', 'browser', 'platform', 'device_name', 'region', 'language'];
            if (!match_normal($target, $browser_save, $key_names)) {
                omp_trace('browser matched failure');
                break;
            }
            //正则表达式匹配UA,如果不匹配则这条任务略过
            $UA = $browser_save['UserAgent'] . @$browser_save['XRequestWith'];
            if (!match_regex($UA, $target['UserAgent'])) {
                omp_trace('UserAgent substr: ' . $UA . '!=' . $target['UserAgent']);
                break;
            }
            //如果是详细匹配,要包括实时的Visiting和Account
            if ($is_detail) {
                $key_names = ['is_first_day', 'is_first_session', 'is_first_pageview', 'is_registed'];
                if (!match_normal($target, $browser_save, $key_names)) {
                    omp_trace('user matched failure');
                    break;
                }
                //正访问网址的正则匹配
                if (!match_regex($browser_save['Visiting'], $target['Visiting'])) {
                    omp_trace('target : ' . $browser_save['Visiting'] . '!=' . $target['Visiting']);
                    break;
                }
                //检查关键字匹配
                $key_names = ['kword_account', 'kword_title', 'kword_submit', 'kword_cart', 'kword_favorite'];
                if (!match_keyword($target, $browser_save, $key_names)) {
                    //todo
                }
                //访问停留时间, 访问页面次数, 总访问页面次数, 来访次数
                $key_names = ['staytime', 'session_pv', 'pageview_count', 'session_count'];
                if (!match_range($browser_save, $target, $key_names)) {
                    omp_trace('match range: failure');
                    break;
                }
            }
            //过关斩将,最后匹配成功了
            $matched = $target;
            omp_trace('match: ' . $target['name']);
            break 2;
        } while (false);
    }
    return $matched;
}