To determine whether a website is accessed by a mobile user or a PC user, we only need to obtain the user's HTTP_USER_AGENT. I first introduced a general Mobile_Detect, the following two examples are self-written and hope to help you. php... to determine whether a website is accessed by a mobile user or a PC user, we only need to obtain the user's HTTP_USER_AGENT. I first introduced a general Mobile_Detect, the following two examples are self-written and hope to help you.
The php code example is as follows:
IsMobile () // Check for any tablet. if ($ detect-> isTablet () // Check for any mobile device, excluding tablets. if ($ detect-> isMobile ()&&! $ Detect-> isTablet () if ($ detect-> isMobile ()&&! $ Detect-> isTablet () // Alternative to $ detect-> isAndroidOS () $ detect-> is ('androiddos '); // Batch usageforeach ($ userAgents as $ userAgent) {$ detect-> setUserAgent ($ userAgent); $ isMobile = $ detect-> isMobile ();} // Version check. $ detect-> version ('iPad '); // 4.3 (float)?>
Php judges mobile phone access, the code is as follows:
Window. location. href = "'. $ string. '"; script';} $ string = str_replace (array (" r "," n "), array ('', ''), $ string ); if (preg_match ('/^ s * location:/is', $ string) {@ header ($ string. "n", $ replace); exit ();} if (emptyempty ($ http_response_code) | PHP_VERSION <'4. 3 ') {@ header ($ string, $ replace);} else {@ header ($ string, $ replace, $ http_response_code) ;}}?>
The js code is as follows:
var isIPhone = /iPhone/i.test(navigator.userAgent),isIPad = /iPad/i.test(navigator.userAgent),isAndroid = /android/i.test(navigator.userAgent);var isIOS = isIPhone || isIPad;alert( "iPhone? " + isIPhone + "tr" + "iPad? " + isIPad + "tr" + "Android? " + isAndroid + "tr" + "iOS? " + isIOS);
Address:
Reprinted at will, but please attach the article address :-)