Home  >  Article  >  Backend Development  >  How to judge PC browser and mobile browser with PHP

How to judge PC browser and mobile browser with PHP

巴扎黑
巴扎黑Original
2016-11-08 09:52:301439browse

function isMobile()
{
// If there is HTTP_X_WAP_PROFILE, it must be a mobile device
if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
{
return true;
}
//If the via information contains wap then It must be a mobile device, some service providers will block this information
if (isset ($_SERVER['HTTP_VIA']))
{
  // If not found, it is false, otherwise it is true
  return stristr($_SERVER['HTTP_VIA'] , "wap") ? true : false;
}
// Brainless method, judge the client flag sent by the mobile phone, compatibility needs to be improved
if (isset ($_SERVER['HTTP_USER_AGENT']))
{
$clientkeywords = array ('nokia',
'sony',
'ericsson',
'mot',
'samsung',
'htc',
'sgh',
'lg',
'sgh',
'sharp',
'sie- ',
                                                                                                                                             'ipod',
'blackberry',
'meizu',
'android',
'netfront ',
        'symbian', 
        'ucweb', 
        'windowsce', 
        'palm', 
                         'operamobi',
'openwave',
'nexusone',
'cldc',
'midp ',
                                                                                                                                                       clientkeywords) . ")/ i", strtolower($_SERVER['HTTP_USER_AGENT'])))
                                                                                                                                                                                  ​ VER[' HTTP_ACCEPT']))
{// If it supports WML and HTML, but WML is a mobile device
IF (Strpos ($ _ _ Server ['http_accept'], 'vand.wap.wml')! == False) && (STRPOS ($ _ Server [ 'HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml')                                                                                                                                       .

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn