예제 #1
0
function wp_log_robots()
{
    global $log_file, $log_file_lock;
    if (isset($_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['REQUEST_URI'])) {
        $is_bot = FALSE;
        if (preg_match("/bot/i", $_SERVER['HTTP_USER_AGENT']) || preg_match("/spider/i", $_SERVER['HTTP_USER_AGENT'])) {
            $is_bot = TRUE;
        }
        if ($is_bot == TRUE) {
            //Ipv6 compatible
            $real_ip = preg_replace("/^::ffff:/i", "", $_SERVER['REMOTE_ADDR']);
            //Log format , you could defined it your self
            $str = date("Y-m-d H:i:s", TIME_STAMP) . "\t" . $real_ip . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
            //Got old records
            $fo = get_old();
            //Check log file write lock if exists
            if (!file_exists($log_file_lock)) {
                //Create file lock prevent write log twice each time
                touch($log_file_lock);
                //Puts new & old records together
                file_put_contents($log_file, $str . $fo);
                //Do not forget remove the log file write lock
                unlink($log_file_lock);
                clearstatcache();
                //For debug purpose
                //echo '<!-- ', $_SERVER['HTTP_USER_AGENT'], $_SERVER['REQUEST_URI'], '-->';
            }
            unset($real_ip);
            unset($str);
            unset($fo);
        }
        unset($is_bot);
    }
}
예제 #2
0
function wp_log_robots()
{
    global $log_file, $log_file_lock;
    if (isset($_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['REQUEST_URI'])) {
        $is_bot = FALSE;
        if (preg_match("/bot/i", $_SERVER['HTTP_USER_AGENT']) || preg_match("/spider/i", $_SERVER['HTTP_USER_AGENT'])) {
            $is_bot = TRUE;
        }
        if ($is_bot == TRUE) {
            $real_ip = preg_replace("/^::ffff:/i", "", $_SERVER['REMOTE_ADDR']);
            $str = date("Y-m-d H:i:s", TIME_STAMP) . "\t" . $real_ip . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
            $fo = get_old();
            if (!file_exists($log_file_lock)) {
                touch($log_file_lock);
                file_put_contents($log_file, $str . $fo);
                unlink($log_file_lock);
                clearstatcache();
            }
            unset($real_ip);
            unset($str);
            unset($fo);
        }
        unset($is_bot);
    }
}