Sometimes it is very useful in some scenarios. Keep it for backup.
Copy codeThe Code is as follows: function is_mobile_request ()
{
$ _ SERVER ['all _ http'] = isset ($ _ SERVER ['all _ http'])? $ _ SERVER ['all _ http']: '';
$ Mobile_browser = '0 ';
If (preg_match ('/(up. browser | up. link | mmp | symbian | smartphone | midp | wap | phone | iphone | ipad | ipod | android | xoom)/I ', strtolower ($ _ SERVER ['HTTP _ USER_AGENT '])
$ Mobile_browser ++;
If (isset ($ _ SERVER ['HTTP _ ACCEPT ']) and (strpos (strtolower ($ _ SERVER ['HTTP _ ACCEPT']), 'application/vnd.wap.xhtml + xml ')! = False ))
$ Mobile_browser ++;
If (isset ($ _ SERVER ['HTTP _ X_WAP_PROFILE '])
$ Mobile_browser ++;
If (isset ($ _ SERVER ['HTTP _ PROFILE '])
$ Mobile_browser ++;
$ Mobile_ua = strtolower (substr ($ _ SERVER ['HTTP _ USER_AGENT '], 0, 4 ));
$ Mobile_agents = array (
'W3c ', 'acs-', 'alav', 'alca', 'amodi', 'audi', 'avany', 'benq', 'bird ', 'blac ',
'Blaz', 'brew', 'cell ', 'cldc', 'cmd-', 'dang', 'Doc', 'Eric ', 'hipt ', 'inno ',
'Ipaq ', 'java', 'glasis', 'dkdi', 'keji', 'leno', 'lg-C', 'lg-d ', 'lg-G', 'lge -',
'Maui', 'maxo', 'midp ', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp ', 'nec -',
'Newt ', 'noki', 'login', 'palm', 'pana ', 'pant', 'Phil', 'play', 'Port', 'prox ',
'Qwap ', 'sage', 'samples', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh -', 'shar ',
'Sie-', 'siem', 'smal', 'smar ', 'sony', '7d-', 'symb','t-m', 'teli ', 'Tim -',
'Tosh', 'tsm-', 'upg1', 'upsi', 'vk-V', 'voda', 'wap-', 'wapa', 'wapi ', 'wapp ',
'Wapr', 'webc', 'winw', 'winw', 'xda', 'xda -'
);
If (in_array ($ mobile_ua, $ mobile_agents ))
$ Mobile_browser ++;
If (strpos (strtolower ($ _ SERVER ['all _ http']), 'operamini ')! = False)
$ Mobile_browser ++;
// Pre-final check to reset everything if the user is on Windows
If (strpos (strtolower ($ _ SERVER ['HTTP _ USER_AGENT ']), 'windows ')! = False)
$ Mobile_browser = 0;
// But WP7 is also Windows, with a slightly different characteristic
If (strpos (strtolower ($ _ SERVER ['HTTP _ USER_AGENT ']), 'windows phone ')! = False)
$ Mobile_browser ++;
If ($ mobile_browser> 0)
Return true;
Else
Return false;
}
Source: http://yi1.com.cn/posts/781
Php determines the browser type based on HTTP_USER_AGENT
Copy codeThe Code is as follows: function browsers (){
Global $ HTTP_USER_AGENT;
If (isset ($ HTTP_USER_AGENT )){
$ SAgent = $ HTTP_USER_AGENT;
} Else {
$ SAgent = $ _ SERVER ['HTTP _ USER_AGENT '];
}
If (strpos ($ sAgent, 'msi ')! ==False & strpos ($ sAgent, 'mac') ===false & strpos ($ sAgent, 'Opera ') === false ){
$ IVersion = (float) substr ($ sAgent, strpos ($ sAgent, 'msie ') + 5, 3 );
Return ($ iVersion> = 5.5 );
} Else if (strpos ($ sAgent, 'gecko /')! = False ){
$ IVersion = (int) substr ($ sAgent, strpos ($ sAgent, 'gecko/') + 6, 8 );
Return ($ iVersion> = 20030210 );
} Else {
Return false;
}
}