How to judge PC browser and mobile browser with PHP

巴扎黑
Release: 2016-11-08 09:52:30
Original
1437 people have browsed it

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')                                                                                                                                       .

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!