コード例 #1
0
function run_test($ua, $parts)
{
    global $i, $passed, $total;
    #echo "target: $ua\n";
    #echo "match: ";
    #print_r($parts);
    $map = array(0 => array('agent', 'agent_version'), 1 => array('engine', 'engine_version'), 2 => array('os', 'os_version'));
    $ret = useragent_decode($ua);
    $pass = 0;
    do {
        foreach ($map as $k => $fields) {
            if ($parts[$k] == '-') {
                if (!is_null($ret[$fields[0]])) {
                    echo "{$i} not ok\n";
                    echo "# {$ua}\n";
                    echo "# expecting blank {$fields['0']}, got {$ret[$fields[0]]}\n";
                    break 2;
                }
                if (!is_null($ret[$fields[1]])) {
                    echo "{$i} not ok\n";
                    echo "# {$ua}\n";
                    echo "# expecting blank {$fields['1']}, got {$ret[$fields[1]]}\n";
                    break 2;
                }
            } else {
                if ($parts[$k]) {
                    list($a, $b) = explode('/', $parts[$k]);
                    if ($ret[$fields[0]] != $a) {
                        echo "{$i} not ok\n";
                        echo "# {$ua}\n";
                        echo "# expecting {$fields['0']} {$a}, got {$ret[$fields[0]]}\n";
                        break 2;
                    }
                    if ($ret[$fields[1]] != $b) {
                        echo "{$i} not ok\n";
                        echo "# {$ua}\n";
                        echo "# expecting {$fields['1']} {$b}, got {$ret[$fields[1]]}\n";
                        break 2;
                    }
                }
            }
        }
        if ($GLOBALS['show_passes']) {
            echo "{$i} ok\n";
            #print_r($ret);
        }
        $passed++;
    } while (0);
    $i++;
    $total++;
}
コード例 #2
0
function useragent_decode_cached($ua)
{
    #
    # cache hit
    #
    if ($GLOBALS['_useragent_cache'][$ua]) {
        $GLOBALS['_useragent_cache'][$ua][1]++;
        return $GLOBALS['_useragent_cache'][$ua][0];
    }
    #
    # miss
    #
    $ret = useragent_decode($ua);
    $GLOBALS['_useragent_cache'][$ua] = array($ret, 1, 0);
    $compact_size = 1.2 * $GLOBALS['_useragent_cache_max'];
    if (count($GLOBALS['_useragent_cache']) >= $compact_size) {
        #echo "compacting cache, since count is ".count($GLOBALS['_useragent_cache'])."\n";
        #
        # sort cache by hits-this, hits-prev DESC
        #
        uasort($GLOBALS['_useragent_cache'], '_useragent_sort_cache');
        #print_r($GLOBALS['_useragent_cache']);
        #
        # trim
        #
        $GLOBALS['_useragent_cache'] = array_slice($GLOBALS['_useragent_cache'], 0, $GLOBALS['_useragent_cache_max']);
        foreach ($GLOBALS['_useragent_cache'] as &$row) {
            $row[2] += $row[1];
            $row[1] = 0;
        }
        #print_r($GLOBALS['_useragent_cache']);
        #exit;
    }
    return $ret;
}
コード例 #3
0
ファイル: ua.php プロジェクト: jacques/flamework
<?php

include '../include/init.php';
loadlib('useragent');
$urls = array("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)");
foreach ($urls as $url) {
    echo "{$url}\n";
    print_r(useragent_decode($url));
    echo "\n";
}
コード例 #4
0
// Example: gzip, deflate, sdch
$client_request_method = $_SERVER['REQUEST_METHOD'];
// Example: GET
$client_connection = $_SERVER['HTTP_CONNECTION'];
// Example: keep-alive
$server_ip = $_SERVER['SERVER_ADDR'];
// Example: 92.51.134.136
$server_port = $_SERVER['SERVER_PORT'];
// Example: 443
$server_protocol = $_SERVER['SERVER_PROTOCOL'];
// Example: HTTP/1.1
$server_name = $_SERVER['SERVER_NAME'];
// Example: localhost
$server_requesttime = $_SERVER['REQUEST_TIME'];
// Example: $UnixTimeStamp
$ua = useragent_decode($client_useragent);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>StarterPage</title>
    <meta name="description" content="StarterPage by Jan Jastrow - for personal use only." />
    <link rel="dns-prefetch" href="//fonts.googleapis.com">
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link type="text/css" rel="stylesheet" href="css/blacktie.css" />
    <link href='http://fonts.googleapis.com/css?family=Exo+2:700|Titillium+Web:400,700' rel='stylesheet' type='text/css'>
</head>
<body>