示例#1
0
function logit($r = '')
{
    global $siteurl, $prefs, $pretext;
    $mydomain = str_replace('www.', '', preg_quote($siteurl, "/"));
    $out['uri'] = @$pretext['request_uri'];
    $out['ref'] = clean_url(str_replace("http://", "", serverSet('HTTP_REFERER')));
    $host = $ip = serverSet('REMOTE_ADDR');
    if (!empty($prefs['use_dns'])) {
        // A crude rDNS cache
        if ($h = safe_field('host', 'txp_log', "ip='" . doSlash($ip) . "' limit 1")) {
            $host = $h;
        } else {
            // Double-check the rDNS
            $host = @gethostbyaddr(serverSet('REMOTE_ADDR'));
            if ($host != $ip and @gethostbyname($host) != $ip) {
                $host = $ip;
            }
        }
    }
    $out['ip'] = $ip;
    $out['host'] = $host;
    $out['status'] = 200;
    // FIXME
    $out['method'] = serverSet('REQUEST_METHOD');
    if (preg_match("/^[^\\.]*\\.?{$mydomain}/i", $out['ref'])) {
        $out['ref'] = "";
    }
    if ($r == 'refer') {
        if (trim($out['ref']) != "") {
            insert_logit($out);
        }
    } else {
        insert_logit($out);
    }
}
示例#2
0
function logit($r = '')
{
    global $siteurl, $id, $record_mentions;
    $mydomain = str_replace('www.', '', $siteurl);
    $out['uri'] = $_SERVER['REQUEST_URI'];
    $out['ref'] = str_replace("http://", "", serverset('HTTP_REFERER'));
    $out['ip'] = @gethostbyaddr($_SERVER['REMOTE_ADDR']);
    if (preg_match("/^[^\\.]*\\.?{$mydomain}/i", $out['ref'])) {
        $out['ref'] = "";
    }
    if ($r == 'refer') {
        if (trim($out['ref']) != "") {
            insert_logit($out);
        }
    } else {
        insert_logit($out);
    }
    if ($id && $record_mentions && $out['ref']) {
        $thepage = getReferringPage('http://' . $out['ref']);
        $refpage = preg_replace("/^(www\\.)?(.*)\\/?\$/Ui", "\$2", $out['ref']);
        $reftitle = tweezePageTitle($thepage);
        $excerpt = tweezeExcerpt($thepage, $out['uri']);
        if ($refpage) {
            mentionInsert(array('id' => $id, 'refpage' => $refpage, 'reftitle' => $reftitle, 'excerpt' => $excerpt));
        }
    }
}
示例#3
0
/**
 * Writes a record to the visitor log using the current visitor's information.
 *
 * This function is used by log_hit(). See it before trying to use this one.
 *
 * The hit is ignore if $r is set to 'refer' and the HTTP REFERER header is empty.
 *
 * @param  string   $r      Type of record to write, e.g. refer
 * @param  int      $status HTTP status code
 * @access private
 * @see    log_hit()
 */
function logit($r = '', $status = 200)
{
    global $prefs, $pretext;
    if (!isset($pretext['request_uri'])) {
        return;
    }
    $host = $ip = (string) remote_addr();
    $protocol = false;
    $referer = serverSet('HTTP_REFERER');
    if ($referer) {
        foreach (do_list(LOG_REFERER_PROTOCOLS) as $option) {
            if (strpos($referer, $option . '://') === 0) {
                $protocol = $option;
                $referer = substr($referer, strlen($protocol) + 3);
                break;
            }
        }
        if (!$protocol || $protocol === 'https' && PROTOCOL !== 'https://') {
            $referer = '';
        } elseif (preg_match('/^[^\\.]*\\.?' . preg_quote(preg_replace('/^www\\./', '', SITE_HOST), '/') . '/i', $referer)) {
            $referer = '';
        } else {
            $referer = $protocol . '://' . clean_url($referer);
        }
    }
    if ($r == 'refer' && !$referer) {
        return;
    }
    if (!empty($prefs['use_dns'])) {
        // A crude rDNS cache.
        if (($h = safe_field('host', 'txp_log', "ip='" . doSlash($ip) . "' limit 1")) !== false) {
            $host = $h;
        } else {
            // Double-check the rDNS.
            $host = @gethostbyaddr($ip);
            if ($host !== $ip && @gethostbyname($host) !== $ip) {
                $host = $ip;
            }
        }
    }
    insert_logit(array('uri' => $pretext['request_uri'], 'ip' => $ip, 'host' => $host, 'status' => $status, 'method' => serverSet('REQUEST_METHOD'), 'ref' => $referer));
}