(PHP) How to determine the current user terminal is the mobile phone and other devices

Source: Internet
Author: User
Tags lenovo

Recommended:

mobile-detect: https://github.com/serbanghita/Mobile-Detect/blob/master/Mobile_Detect.php

Detect Mobile Browser: http://detectmobilebrowsers.com/

Other methods (concrete effects to be practiced):

/** * * Based on the various browser-specific strings included in PHP $_server[' http_user_agent ') to determine whether they belong to a PC or a mobile * @author discuz3x * @lastmodify 2014-04-09 * @return BOOL */function checkmobile () {global $_g; $mobile = Array ();//$_server[' Http_user_agen in each touch browser T '] contains a string array of static $touchbrowser _list =array (' iphone ', ' Android ', ' phone ', ' mobile ', ' wap ', ' NetFront ', ' Java ', ' opera m Obi ', ' Opera Mini ', ' UCWeb ', ' Windows CE ', ' Symbian ', ' series ', ' webOS ', ' Sony ', ' BlackBerry ', ' dopod ', ' Nokia ', ' SAMSU  Ng ', ' palmsource ', ' xda ', ' pieplus ', ' Meizu ', ' MIDP ', ' CLDC ', ' Motorola ', ' Foma ', ' DoCoMo ', ' up.browser ', ' Up.link ', ' Blazer ', ' helio ', ' hosin ', ' Huawei ', ' Novarra ', ' Coolpad ', ' webOS ', ' techfaith ', ' palmsource ', ' Alcatel ', ' Amoi ', ' kt Ouch ', ' Nexian ', ' Ericsson ', ' Philips ', ' Sagem ', ' wellcom ', ' Bunjalloo ', ' Maui ', ' smartphone ', ' iemobile ', ' spice ', ' Bi Rd ', ' zte-', ' longcos ', ' Pantech ', ' Gionee ', ' portalmmm ', ' Jig browser ', ' hiptop ', ' BenQ ', ' Haier ', ' ^lct ', ' 320x320 ', ' 240x320 ', ' 176x220 ');//wIndow Mobile Browser Array "guessed" Static $mobilebrowser _list =array (' Windows Phone '),//wap the string array contained in the $_server[' Http_user_agent ' in the browser static $wmlbrowser _list = Array (' Cect ', ' compal ', ' ctl ', ' LG ', ' nec ', ' tcl ', ' Alcatel ', ' Ericsson ', ' bird ', ' Daxian ', ' DBT ' El ', ' eastcom ', ' Pantech ', ' Dopod ', ' Philips ', ' Haier ', ' Konka ', ' Kejian ', ' Lenovo ', ' BenQ ', ' mot ', ' Soutec ', ' Nokia ', ' Sagem ', ' sgh ', ' sed ', ' capitel ', ' Panasonic ', ' SonyEricsson ', ' sharp ', ' amoi ', ' Panda ', ' ZTE '; $pad _list = array (' pad ', ' gt-p1000 '); $useragent = Strtolower ($_server[' http_user_agent '); if (Dstrpos ($useragent, $pad _list)) {return false;} if ($v = Dstrpos ($useragent, $mobilebrowser _list, True)) {$_g[' mob  Ile '] = $v; Return ' 1 ';  } if ($v = Dstrpos ($useragent, $touchbrowser _list, True)) {$_g[' mobile '] = $v; Return ' 2 ';  } if ($v = Dstrpos ($useragent, $wmlbrowser _list))) {$_g[' mobile '] = $v; Return ' 3 '; WML Edition} $brower = Array (' Mozilla ', ' Chrome ', ' Safari ', ' opera ', ' m3gate ', ' winwap ', ' Openwave ', ' myop '); if (Dstrpos ($useragENT, $brower)) return false; $_g[' mobile ' = ' unknown ';//for browsers of unknown type, use the $_get[' mobile ' parameter to determine if it is a mobile browser if (Isset ($_g[' mobiletpl '][$_get[' mobile ']) {return true;} else {return false;}} /** * Determine if the element string in $arr appears in $string * @param $string $_server[' http_user_agent '] * @param $arr browser $_server[ The string that must be contained in ' Http_user_agent '] @param $returnvalue return the browser name or return a Boolean value, true to return the browser name, False to return a Boolean value of "Default" * @author Discuz 3x * @lastmodify 2014-04-09 */function dstrpos ($string, $arr, $returnvalue = False) {if (empty ($string)) return false;   foreach ((array) $arr as $v) {if (Strpos ($string, $v)!== false) {$return = $returnvalue? $v: true;  return $return; }} return false;}

<?phpfunction 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 associations block the information if (Isset ($_server[' Http_via ')) {//Cannot find for flase, otherwise true re Turn stristr ($_server[' Http_via '), "WAP")?    True:false; }//Brain residue method, determine the mobile phone sent by the client flag, compatibility needs to be improved 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            OID ', ' NetFront ', ' Symbian ', ' UCWeb ', ' windowsce ', ' palm ',    ' Operamini ', ' operamobi ', ' Openwave ',        ' Nexusone ', ' cldc ', ' MIDP ', ' wap ', ' mobile '; Look for the keyword if (Preg_match ("/(") of the phone's browser from Http_user_agent. Implode (' | ', $clientkeywords).        ")/I", Strtolower ($_server[' http_user_agent '))) {return true;        }}//protocol method, because it may not be accurate, put to the Last Judgment 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 before HTML the mobile device if ((Strpos ($_server[' http_accept '), ' VND.WAP.WML ')!== false) && (STRP OS ($_server[' http_accept '), ' text/html ') = = = False | |        (Strpos ($_server[' http_accept '), ' vnd.wap.wml ') < Strpos ($_server[' http_accept '], ' text/html '))))        {return true; }} return false;} ?>

 

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 (' acs-', ' Alav ', ' Alca ', ' amoi ', ' Audi ', ' Avan ', ' BenQ ', ' bird ', ' Blac ', ' Blaz ', ' brew ', ' CE ' ll ', ' cldc ', ' cmd-', ' Dang ', ' doco ', ' Eric ', ' Hipt ', ' Inno ', ' iPAQ ', ' Java ', ' Jigs ', ' kddi ', ' Keji ', ' Leno ', ' lg-c ', ' lg-d ', ' Lg-g ', ' lge-', ' Maui ', ' Maxo ', ' MIDP ', ' mits ', ' mmef ', ' mobi ', ' mot-', ' moto ', ' mwbp ', ' nec-', ' newT ', ' Noki ', ' oper ', ' palm ', ' pana ', ' Pant ', ' Phil ', ' play ', ' Port ', ' ProX ', ' qwap ', ' sage ', ' Sams ', ' Sany ', ' sch-', ' sec-', ' Send ', ' Seri ', ' sgh-', ' shar ', ' sie-', ' Siem ', ' smal ', ' Smar ', ' Sony ', ' sph-', ' symb ', ' t-mo ', ' 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 are on Windows if (Strpos (Strtolower ($_server[' http_user_agent ')), ' win   Dows ')!== false) $mobile _browser=0; But WP7 are also Windows, with a slightly different characteristic if (Strpos (strtolower ' $_server['),   ' Windows Phone ')!== false) $mobile _browser++;   if ($mobile _browser>0) return true; else return false;

How the

(PHP) program determines that the current user terminal is a mobile terminal such as a mobile phone

Related Article

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.