使用php判断浏览器是pc还是手机

function isMobile()
{
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset (KaTeX parse error: Double subscript at position 16: _SERVER['HTTP_X_̲WAP_PROFILE']))…_SERVER[‘HTTP_VIA’]))
{
// 找不到为flase,否则为true
return stristr(KaTeX parse error: Expected 'EOF', got '}' at position 49: …e : false; }̲ // 脑残法,判断…_SERVER[‘HTTP_USER_AGENT’]))
{
$clientkeywords = array (‘nokia’,
‘sony’,
‘ericsson’,
‘mot’,
‘samsung’,
‘htc’,
‘sgh’,
‘lg’,
‘sharp’,
‘sie-’,
‘philips’,
‘panasonic’,
‘alcatel’,
‘lenovo’,
‘iphone’,
‘ipod’,
‘blackberry’,
‘meizu’,
‘android’,
‘netfront’,
‘symbian’,
‘ucweb’,
‘windowsce’,
‘palm’,
‘operamini’,
‘operamobi’,
‘openwave’,
‘nexusone’,
‘cldc’,
‘midp’,
‘wap’,
‘mobile’
);
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode(’|’, c l i e n t k e y w o r d s ) . " ) / i " , s t r t o l o w e r ( clientkeywords) . ")/i", strtolower( _SERVER[‘HTTP_USER_AGENT’])))
{
return true;
}
}
// 协议法,因为有可能不准确,放到最后判断
if (isset (KaTeX parse error: Expected '}', got 'EOF' at end of input: … if ((strpos(_SERVER[‘HTTP_ACCEPT’], ‘vnd.wap.wml’) !== false) && (strpos( S E R V E R [ H T T P A C C E P T ] , t e x t m l ) = = = f a l s e ( s t r p o s ( _SERVER[&#x27;HTTP_ACCEPT&#x27;], &#x27;textml&#x27;) === false || (strpos( _SERVER[‘HTTP_ACCEPT’], ‘vnd.wap.wml’) < strpos($_SERVER[‘HTTP_ACCEPT’], ‘textml’))))
{
return true;
}
}
return false;
}

猜你喜欢

转载自blog.csdn.net/weixin_43365995/article/details/88950721
今日推荐