Determine if "Mobile Access Access" "PHP"

Source: Internet
Author: User

Take the SP framework as an example: <?phpclass main extends Spcontroller//main is a PC-side ingress controller, equivalent to the default Indexcontroller.php{function __construct () {   Parent::__construct ();  if ($this->ismobile ()) {   //redirect to mobile   header ("  Location:http://$_server[http_host]/mobile.php "); mobile.php for mobile port entry files    exit; }else{   .... }  }  <?php  class Spcontroller { /**  * Whether mobile Access   *  * @return bool  */ public function IsMobile ()  {     //If you have 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 this information      if (isset ($_server[' Http_via '))      {         //not found for flase, otherwise true         return stristr ($_server[' Http_via '), " WAP ")? true:false;&nbsp    }     //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 ',        &NB Sp     ' Sony ',              ' Ericsson ',            and nbsp; ' Mot ',              ' Samsung ',              ' HTC ', &nbsp ;             ' SGH ',              ' LG ',      & nbsp       ' sharp ',              ' sie-',          &NBS P   ' Philips ',              ' Panasonic ',            &NBS P; ' Alcatel ',              ' Lenovo ',              ' IphonE ',              ' ipod ',              ' BlackBerry ', &NB Sp             ' Meizu ',              ' Android ',    & nbsp         ' NetFront ',              ' Symbian ',      &NBSP ;       ' UCWeb ',              ' WindowsCE ',              ' palm ',              ' Operamini ',              ' Operamobi ',              ' Openwave ',            &N BSP; ' Nexusone ',              ' CLDC ',              ' MIDP ', &N Bsp             ' WAP ',              ' mobile '     &NBSP ;       );         //find mobile browser keywords from http_user_agent          if (Preg_match ("/("). Implode (' | ', $clientkeywords). ")/I", Strtolower ($_server[' http_user_agent ')))          {          nbsp  return true;         }     }     //protocol, as it may be inaccurate and put to the final Judgment & nbsp    if (isset ($_server[' http_accept '))      {         // If only WML is supported and HTML is not supported then it must be mobile          //if WML and HTML are supported, but WML is mobile before HTML,          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;  &NBsp      }     }     return false; }

Determine if the Mobile Access Access "PHP"

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.