PHP determines whether it is a mobile phone or PC, and whether it is a code instance of WeChat browser

Source: Internet
Author: User
This article mainly introduces PHP to determine whether it is a mobile phone or PC, and PHP to determine whether it is a browser, which has some reference value, interested friends can refer to this article for details on PHP's judgment on the mobile phone or PC, and PHP's judgment on whether it is a browser, which has a certain reference value, for more information, see

The examples in this article share two examples of PHP judgment. one is PHP's judgment on the mobile phone or PC, and the other is PHP's judgment on whether the browser is used for your reference. the specific content is as follows:

1. determine whether it is a mobile phone


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, it must be a mobile device. some service providers will block this information if (isset ($ _ SERVER ['http _ VE']) {// cannot be found as flase; otherwise, it is true return stristr ($ _ SERVER ['http _ vean'], "wap ")? True: false;} // identify the client flag sent by the mobile phone. the compatibility needs to be improved. Here, 'micromessenger 'is the computer if (isset ($ _ 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 ', 'micromessenger '); // from HTT Search for the keyword if (preg_match ("/(". implode ('|', $ clientkeywords ). ")/I", strtolower ($ _ SERVER ['http _ USER_AGENT ']) {return true ;}// resolution method, because it may be inaccurate, put it at the end to determine if (isset ($ _ SERVER ['http _ ACCEPT ']) {// if only wml is supported and html is not supported, it must be a mobile device // if wml and html are supported, but wml is a mobile device before html (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ')! = False) & (strpos ($ _ SERVER ['http _ ACCEPT '], 'text/html ') === false | (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ') <strpos ($ _ SERVER ['http _ ACCEPT'], 'text/html ') {return true ;}} return false ;}

2. determine whether it is a built-in browser


function isWeixin() {   if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {     return true;   } else {    return false;   }}

The above is the details of PHP's code instance for determining whether the browser is a mobile phone or PC. For more information, see other related articles in the first PHP community!

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.