PHP to determine if the current browsing device is a mobile phone

Source: Internet
Author: User

Today see a PHP to determine whether it is a handheld device code,

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 VIA information contains WAP, it must be a mobile device, some service associations block the information if  (isset  ($_server[' Http_via ')) {//  cannot be found as flase, Otherwise truereturn stristr ($_server[' Http_via '],  "WAP")  ? true : false;}   Brain residue method, determine the mobile phone to send the client logo, 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 ',              ' NetFront ', &NBsp;            ' Symbian ',              ' UCWeb ',              ' windowsce ',             ' palm ',              ' Operamini ',              ' Operamobi ',              ' Openwave ',             ' Nexusone ',             ' CLDC ',              ' MIDP ',              ' WAP ',             ' mobile '          );        //  Find the keywords in the phone browser from http_user_agent         if  (Preg_match ("/("  . implode (' | '),  $ clientkeywords)  .  ")/I",  strtolower ($_server[' http_user_agent '))) {         return true;        }}//  Agreement Law, Because there may be inaccuracies, put to the Last Judgment if  (isset  ($_server[' http_accept ')) {//  if only WML is supported and HTML is not supported that must be a mobile device//  If WML and HTML are supported but WML before HTML is mobile device if  ((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;}


PHP to determine if the current browsing device is a mobile phone

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.