Php judges whether mobile phone browsing or web browsing, and executes the corresponding simple action instance _ php instance

Source: Internet
Author: User
The following small series will provide you with a simple example of php to determine whether mobile browser or web browser is used and perform the corresponding action. I think this is quite good. I will share it with you now and give you a reference. Let's take a look at it together. I have been searching for it on the Internet for a long time. let's record it.

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', 'cento', 'mogin', 'avantgo ', 'Opera mobi ', 'j2'/MIDP ', 'Smartphone', 'Go. web ', 'Palm', 'ipaq '); $ mobile_token_list = array ('Profile/MIDP', 'configuration/CLDC-', '2017 × 160 ', '000000', '000000', '000000', '000000', '000000', 'up. browser ', 'Up. link ', 'symbian OS', '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 it is a mobile phone, execute the Jump} else {header ('Location :. /web/index. php '); // if it is not on the mobile phone, execute the Jump}

The above php judges whether mobile browsing is web browsing, and executes a simple example of the corresponding action to share all the content with you. I hope to give you a reference, and I hope you can support your own home.

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.