本文整理汇总了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));
}
}
示例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;
}
示例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;
}
}
示例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));
}
示例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);
}
示例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;)");
}
}
示例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);
}
示例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);
}
示例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;
}
示例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');
}
示例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;
}
示例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;
}
示例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();
}
示例14: __construct
public function __construct()
{
$this->useragent = parse_user_agent();
}
示例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'];
}