PHP Judge Mobile browsing or web browsing, and perform the corresponding action simple instance _php instance

Source: Internet
Author: User

Just need to find a long time on the internet, to record the

function IsMobile () {$useragent =isset ($_server[' http_user_agent '])? $_server[' Http_user_agent ']: ';    
  $useragent _commentsblock=preg_match (' |\ (. *?\) | ', $useragent, $matches) >0? $matches [0]: '; 
        function Checksubstrs ($substrs, $text) {foreach ($substrs as $substr) if (False!==strpos ($text, $substr)) { 
      return true; 
  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-', ' 160x160 ', ' 176x220 ', ' 240x240 ', ' 240x320 ', ' 320x The ', ' 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 ()) {header (' Location:./app/index.php ');//If for mobile, execute jump} else{header (' Location:./web/index.php '); If not on the handset side, perform the Jump}

Above this PHP to judge mobile browsing or web browsing, and the implementation of the corresponding action simple example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat 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.