Php judges whether mobile browsing is web browsing, and executes the corresponding action, phpweb
Yes. I have been searching for it online for a long time. record it.
1 function isMobile () {2 $ useragent = isset ($ _ SERVER ['HTTP _ USER_AGENT '])? $ _ SERVER ['HTTP _ USER_AGENT ']: ''; 3 $ useragent_commentsblock = preg_match (' | \(.*? \) | ', $ Useragent, $ matches)> 0? $ Matches [0]: ''; 4 function CheckSubstrs ($ substrs, $ text) {5 foreach ($ substrs as $ substr) 6 if (false! = Strpos ($ text, $ substr) {7 return true; 8} 9 return false; 10} 11 $ mobile_ OS _list = array ('Google Wireless transcoder ', 'windows CE ', 'windowsce', 'symbian ', 'android', 'armv6l', 'armv5', 'mobile', 'centos ', 'moyun ', 'avantgo ', 'Opera Mobi', 'j2's/MIDP ', 'smartphone', 'go. web ', 'palm', 'ipaq '); 12 $ 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'); 13 14 $ found_mobile = CheckSubstrs ($ mobile_ OS _list, $ useragent_commentsblock) | 15 CheckSubstrs ($ mobile_token_list, $ useragent ); 16 17 if ($ found_mobile) {18 return true; 19} else {20 return false; 21} 22} 23 if (isMobile () {24 header ('location :. /app/index. php '); // if it is a mobile phone, execute the jump 25} 26 else {27 header ('location :. /web/index. php '); // if it is not on the mobile phone end, execute the jump 28}