How does php determine whether the client is a pc or a mobile phone?

Source: Internet
Author: User
How can I determine whether a web page is viewed on a pc or a mobile phone? How can I determine whether a web page is viewed on a pc or a mobile phone?

Reply content:

How can I determine whether a web page is viewed on a pc or a mobile phone?

PHPA library for mobile phone detection is very famous.Mobile-Detect
Address: https://packagist.org/packages/mobiledetect/mobiledetectlib


  0?$matches[0]:'';    function CheckSubstrs($substrs,$text){        foreach($substrs as $substr){            if(false!==strpos($text,$substr)){                return true;            }else{                return false;            }        }    }    $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');    $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');         $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) || CheckSubstrs($mobile_token_list,$useragent);         if ($found_mobile){        return true;    }else{          return false;    }}if (isMobile())echo 'phone';elseecho 'pc';?>

Detailed link description

Judge UA.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.