当前位置: 首页>>代码示例>>PHP>>正文


PHP parse_user_agent函数代码示例

本文整理汇总了PHP中parse_user_agent函数的典型用法代码示例。如果您正苦于以下问题:PHP parse_user_agent函数的具体用法?PHP parse_user_agent怎么用?PHP parse_user_agent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_user_agent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insertAccessLogging

 /**
  * Inserts the access log information in
  * the database
  *
  * @param array $alogs Access Log lines
  * @param       $fromServer array The sender of these access logs
  *
  * @throws \Kassner\LogParser\FormatException
  */
 public function insertAccessLogging(array $alogs, $fromServer, $parseString)
 {
     try {
         if (!(count($alogs) > 0)) {
             return;
         }
         $parser = new \Kassner\LogParser\LogParser();
         $parser->setFormat($parseString);
         $toBeInserted = [];
         foreach ($alogs as $line) {
             $userSpec = $parser->parse($line);
             if ($userSpec->host === '::1') {
                 continue;
             }
             $userSpec->device = parse_user_agent($userSpec->HeaderUserAgent);
             $city = new Reader(database_path() . '/GeoLite2-City.mmdb');
             $geoRecord = $city->city($userSpec->host);
             $userSpec->fromServer = $fromServer;
             $userSpec->location = ['city' => $geoRecord->city->name, 'country' => $geoRecord->country->name];
             $userSpec->createdAt = time();
             $toBeInserted[] = $userSpec;
         }
         $this->mongoCollectionForAccess->batchInsert($toBeInserted);
     } catch (\Exception $e) {
         error_log(print_r($e, true));
     }
 }
开发者ID:SystemBro,项目名称:SystemBroApp,代码行数:36,代码来源:Analytics.php

示例2: refer_zilla_stat_show

function refer_zilla_stat_show($id)
{
    global $ZillaName, $wpdb, $ReferZillaTable;
    $r = '';
    $ReferZillaTableStat = $ReferZillaTable . 'stat';
    $sql = "SELECT link, redirect FROM {$ReferZillaTable} where (id={$id})";
    $dat = $wpdb->get_results($sql);
    $r = '<h3>Cliks for `' . $dat[0]->link . '`</h3>';
    //.$dat[0]->redirect.'<hr>';
    $r .= '<table>';
    $r .= '<tr><th>Id</th><th>Time</th><th>Refer</th><th>Country</th><th>IP</th><th>Page</th><th>Browser</th><th>Platform</th></tr>';
    $sql = "SELECT id, dt, ref, ip, cn, agent,page FROM {$ReferZillaTableStat} where (id_link={$id}) order by dt desc";
    $stats = $wpdb->get_results($sql);
    include_once "UserAgentParser.php";
    foreach ($stats as $stat) {
        $a = '<td colspan=2>Not Set<td>';
        if (!is_null($stat->agent)) {
            $ag = parse_user_agent($stat->agent);
            $a = '<td>' . $ag['browser'] . '</td><td>' . $ag['platform'] . '</td>';
        }
        $ref = $stat->ref;
        if (strlen($ref) > 50) {
            $ref = substr($ref, 0, 50) . '...';
        }
        $r .= '<tr><td>' . $stat->id . '</td><td>' . $stat->dt . '</td><td>' . $ref . '</td><td>' . $stat->cn . '</td><td>' . $stat->ip . '</td><td>' . $stat->page . '</td>' . $a . '</tr>';
    }
    $r .= '</table>';
    return $r;
}
开发者ID:Repazol,项目名称:refer-zilla,代码行数:29,代码来源:refer-zilla-statistic.php

示例3: perform

 /**
  * Perform command.
  */
 public function perform()
 {
     try {
         $entry = [];
         $parser = new \Kassner\LogParser\LogParser();
         $parser->setFormat('%h %l %u %t "%r" %>s %O "%{Referer}i" \\"%{User-Agent}i"');
         $lines = file('/var/log/apache2/access.log', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
         foreach ($lines as &$line) {
             $userSpec = $parser->parse($line);
             $userSpec->device = parse_user_agent($userSpec->HeaderUserAgent);
             $city = new Reader(__DIR__ . '/../Database/GeoLite2-City.mmdb');
             $country = new Reader(__DIR__ . '/../Database/GeoLite2-Country.mmdb');
             $userSpec->location = ['city' => $city->city($userSpec->host)->city->name, 'country' => $country->country($userSpec->host)->country->name];
             $entry[] = $userSpec;
         }
         file_put_contents('/var/log/apache2/access.log', '');
     } catch (\Exception $e) {
         file_put_contents('/var/log/apache2/access.log', '');
     }
     if (count($entry) > 0) {
         AccessReport::odmCollection()->batchInsert($entry);
         print "wrote " . count($entry) . " records";
     } else {
         print 0;
     }
 }
开发者ID:jwdeitch,项目名称:systembroBackend,代码行数:29,代码来源:LogAggregatorCommand.php

示例4: model

 /**
  * @param string $userAgent
  * @return UserAgent
  */
 public static function model($userAgent = null)
 {
     if (null === $userAgent) {
         $ua = static::getDefaultUserAgent();
     }
     return new static(parse_user_agent($userAgent));
 }
开发者ID:xjflyttp,项目名称:yii2-user-agent,代码行数:11,代码来源:UserAgent.php

示例5: test_pase_user_agent_empty

 function test_pase_user_agent_empty()
 {
     $expected = array('platform' => null, 'browser' => null, 'version' => null);
     $result = parse_user_agent('');
     $this->assertEquals($result, $expected);
     $result = parse_user_agent('Mozilla (asdjkakljasdkljasdlkj) BlahBlah');
     $this->assertEquals($result, $expected);
 }
开发者ID:nmdimas,项目名称:yii2-user-agent-parser,代码行数:8,代码来源:UserAgentParserTest.php

示例6: __construct

 /**
  * Browser constructor.
  */
 public function __construct()
 {
     try {
         $this->useragent = parse_user_agent();
     } catch (\InvalidArgumentException $e) {
         $this->useragent = parse_user_agent("Mozilla/5.0 (compatible; Unknown;)");
     }
 }
开发者ID:ulilu,项目名称:grav-toctoc,代码行数:11,代码来源:Browser.php

示例7: goToNewUrl

 public function goToNewUrl(Request $request, $code)
 {
     $url = Rule::where('short_url', $code)->first();
     if (!$url) {
         $view = view('errors.404');
         return response($view, 404);
     }
     $user_agent = parse_user_agent($request->header('user-agent'));
     $rdr = ['ip_address' => $request->getClientIp(), 'referer' => $request->header('referer'), 'browser' => $user_agent['browser'], 'platform' => $user_agent['platform'], 'country' => $request->header('CF-IPCountry'), 'browser_version' => $user_agent['version']];
     Visit::create($rdr);
     return redirect()->to($url->long_url);
 }
开发者ID:anyTV,项目名称:gototm,代码行数:12,代码来源:RedirectController.php

示例8: save

 /**
  * Saves data
  * @return bool
  * @uses get()
  * @uses $file
  */
 public function save()
 {
     //Gets existing data
     $data = $this->get();
     $agent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
     $ip = getClientIp();
     //Clears the first log (last in order of time), if it has been saved
     //  less than an hour ago and the user agent and the IP address are
     //  the same
     if (!empty($data[0]) && (new Time($data[0]->time))->modify('+1 hour')->isFuture() && $data[0]->agent === $agent && $data[0]->ip === $ip) {
         unset($data[0]);
     }
     //Adds log for current request
     array_unshift($data, (object) am(['ip' => getClientIp(), 'time' => new Time()], parse_user_agent(), compact('agent')));
     //Keeps only the first records
     $data = array_slice($data, 0, config('users.login_log'));
     //Serializes
     $data = serialize($data);
     return $this->file->write($data);
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:26,代码来源:LoginLogger.php

示例9: parseUserAgent

 /**
  * @param string $ua
  *
  * @return UserAgent
  */
 protected static function parseUserAgent($ua = '')
 {
     $ua = (string) $ua;
     if (empty($ua)) {
         $ua = \Yii::$app->request->userAgent;
         if (empty($ua)) {
             return new UserAgent();
         }
     }
     $parsedUserAgent = parse_user_agent($ua);
     $userAgent = new UserAgent();
     $userAgent->ua = $ua;
     if (is_array($parsedUserAgent) && isset($parsedUserAgent['platform'], $parsedUserAgent['browser'], $parsedUserAgent['version'])) {
         $userAgent->platform = (string) $parsedUserAgent['platform'];
         $userAgent->browser = (string) $parsedUserAgent['browser'];
         $userAgent->version = (string) $parsedUserAgent['version'];
         if (!empty($userAgent->platform) || !empty($userAgent->browser) || !empty($userAgent->version)) {
             $userAgent->successfullyParsed = true;
         }
     }
     return $userAgent;
 }
开发者ID:nox-it,项目名称:yii2-nox-user-agent-parser,代码行数:27,代码来源:UserAgentParser.php

示例10: log_in

function log_in($params)
{
    if (isset($params['username'])) {
        $db = connect_database();
        $user = $db->query('SELECT id, organization, email, username, `password`, lang, timezone, auth, reset_code FROM `user` WHERE username = \'' . $params['username'] . '\'');
        if ($user = row_assoc($user)) {
            if ($user['password'] == md5($params['password'] . ':' . COMMON_SALT)) {
                unset($user['password']);
                //$user['auth'] = array_merge(json_decode(PUBLIC_MODULES, true), json_decode($user['auth'], true));
                //$_SESSION['user'] = $user;
                if ($user['reset_code'] != '') {
                    flash_message('Someone has requested to reset your password. We recommend you change your password now.', 'warning');
                }
                //
                global $user_id, $acl, $ip;
                include 'interfaces/user_agent_parser.php';
                $login = $db->query('SELECT id FROM login WHERE cookie = \'' . $user_id . '\'');
                // user_id = '.$user['id'].' OR
                $loginRec = array('remember' => isset($params['remember']) ? 1 : 0, 'user_id' => $user['id'], 'session' => session_id(), 'ip' => $ip, 'last_login' => date('Y-m-d H:i:s'), 'useragent' => json_encode(parse_user_agent($_SERVER['HTTP_USER_AGENT'])));
                if ($login = row_assoc($login)) {
                    $acl[] = 'edit';
                    $loginRec['id'] = $login['id'];
                    $db->update('login', $loginRec);
                } else {
                    $acl[] = 'add';
                    $loginRec['cookie'] = $user_id;
                    $db->insert('login', $loginRec);
                }
                //
                setcookie('user_id', $user_id, time() + 3600 * 24 * 365 * 5, PATH);
                if (isset($_SESSION['REDIRECT_AFTER_SIGNIN']) && $user['reset_code'] == '') {
                    $tmp = $_SESSION['REDIRECT_AFTER_SIGNIN'];
                    unset($_SESSION['REDIRECT_AFTER_SIGNIN']);
                    header('location:' . (substr($tmp, 0, strlen(BASE_URL)) == BASE_URL ? '' : BASE_URL) . $tmp);
                } else {
                    redirect('user', 'index');
                }
            }
        }
        flash_message('Wrong username or password.', 'error');
    }
    $data['html_head'] = array('title' => 'Log In');
}
开发者ID:Villvay,项目名称:veev,代码行数:43,代码来源:user.module.php

示例11: get_user_habit_data

 /**
  * Put together the user habit data associative array that will later be part
  * of the [options, user habit data] JSON object sent to the erlang backend.	 
  */
 private static function get_user_habit_data($term)
 {
     // Parse the user agent string so we get the components we need
     $user_agent_strings = parse_user_agent();
     $browser = $user_agent_strings['browser'];
     $browser_version = $user_agent_strings['version'];
     $platform = $user_agent_strings['platform'];
     $user_habit_data = array('term' => $term, 'timestamp' => time(), 'session_id' => session_id(), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'browser' => $browser, 'browser_version' => $browser_version, 'platform' => $platform);
     return $user_habit_data;
 }
开发者ID:TacoVox,项目名称:HashTux,代码行数:14,代码来源:request.php

示例12: get_UserAgent

 public function get_UserAgent()
 {
     // Parse the agent stirng.
     try {
         $agent = parse_user_agent();
     } catch (Exception $e) {
         $agent = array('browser' => 'Unknown', 'platform' => 'Unknown', 'version' => 'Unknown');
     }
     // null isn't a very good default, so set it to Unknown instead.
     if ($agent['browser'] == null) {
         $agent['browser'] = "Unknown";
     }
     if ($agent['platform'] == null) {
         $agent['platform'] = "Unknown";
     }
     if ($agent['version'] == null) {
         $agent['version'] = "Unknown";
     }
     // Uncommon browsers often have some extra cruft, like brackets, http:// and other strings that we can strip out.
     $strip_strings = array('"', "'", '(', ')', ';', ':', '/', '[', ']', '{', '}', 'http');
     foreach ($agent as $key => $value) {
         $agent[$key] = str_replace($strip_strings, '', $agent[$key]);
     }
     return $agent;
 }
开发者ID:bqevin,项目名称:wp-shopeasy,代码行数:25,代码来源:statistics.class.php

示例13: getInfo

 /**
  * Parses a user agent string into its important parts
  *      
  * @param string $u_agent
  * @return array an array with browser, version and platform keys
  */
 public static function getInfo () {
     return parse_user_agent();
 }
开发者ID:anandcyberlinks,项目名称:cyberlinks-demo,代码行数:9,代码来源:User_Agent.php

示例14: __construct

 public function __construct()
 {
     $this->useragent = parse_user_agent();
 }
开发者ID:miguelramos,项目名称:grav,代码行数:4,代码来源:Browser.php

示例15: detect_browser

function detect_browser($user_agent = NULL, $return_array = FALSE)
{
    global $cache;
    if (is_null($user_agent) && $cache['detect_browser']) {
        return $cache['detect_browser'];
    }
    include_once $GLOBALS['config']['html_dir'] . '/includes/Mobile_Detect.php';
    $detect = new Mobile_Detect();
    if (!is_null($user_agent)) {
        // Set custom User-Agent
        $detect->setUserAgent($user_agent);
    } else {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
    }
    $type = 'generic';
    if ($detect->isMobile()) {
        // Any phone device (exclude tablets).
        $type = 'mobile';
        if ($detect->isTablet()) {
            // Any tablet device.
            $type = 'tablet';
        }
    }
    if ($return_array) {
        // Load additional function
        if (!function_exists('parse_user_agent')) {
            include_once $GLOBALS['config']['html_dir'] . '/includes/UserAgentParser.php';
        }
        // Detect Browser name, version and platform
        $ua_info = parse_user_agent($user_agent);
        $cache['detect_browser'] = array('user_agent' => $user_agent, 'type' => $type, 'browser' => $ua_info['browser'] . ' ' . $ua_info['version'], 'platform' => $ua_info['platform']);
    } else {
        $cache['detect_browser'] = $type;
    }
    return $cache['detect_browser'];
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:36,代码来源:functions.inc.php


注:本文中的parse_user_agent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。