php检测useragent版本示例
<?php
define('IE', 1);
define('FIREFOX', 2);
define('CHROME', 3);
define('OPERA', 4);
class UserAgentDetect
{
static $version = array();
static $userAgent = '';
static function getUserAgent()
{
$header = getallheaders();
self :: $userAgent = $header['User-Agent'];
}
function findUserAgentByKey($ua, $key)
{
$len = strlen($key);
$start = strpos($ua, $key);
$pos = strpos($ua, ' ', $start + $len + 1);
return substr($ua, $start + $len, $pos - $len - $start);
}
static function detectUserAgent()
{
self :: getUserAgent();
if (strpos(self :: $userAgent, 'MSIE') != null)
{
self :: $version[] = IE;
self :: $version[] =self:: findUserAgentByKey(self :: $userAgent, 'MSIE');
}
else if (strpos(self :: $userAgent, 'Gecko/') != null)
{
self :: $version[] = FIREFOX;
self :: $version[] =self:: findUserAgentByKey(self :: $userAgent, 'Firefox/');
}
else if (strpos(self :: $userAgent, 'AppleWebKit/') != null)
{
self :: $version[] = CHROME;
self :: $version[] = self:: findUserAgentByKey(self :: $userAgent, 'Chrome/');
}
else if (strpos(self :: $userAgent, 'Presto/') != null)
{
self :: $version[] = OPERA;
self :: $version[] = self:: findUserAgentByKey(self :: $userAgent, 'Opera/');
}
else
{
}
return self :: $version;
}
function matchUserAgent($ua, $key)
{
preg_match("/$key.([^\s]*?)\s/", $ua, $out);
return $out[1];
}
}
$ua=UserAgentDetect::detectUserAgent();
print_r($ua);
相关文章
laravel技巧之查询构造器Query Builder叠加链式调用的方法
这篇文章主要给大家介绍了关于laravel技巧之查询构造器Query Builder叠加链式调用的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友下面来一起看看吧。2017-12-12SCP远程VPS快速搬家和WDCP升级php5.3安装memcached和eaccelerator教程
本文除了要演示一下SCP方法外,还要分享一下WDCP升级php5.3后如何成功安装memcached和eaccelerator,感兴趣的朋友一起看看吧2017-07-07
最新评论