PHP website to determine whether a user is a mobile phone access method

Source: Internet
Author: User
Tags php framework php website

In some cases, we need to determine whether the user is using a mobile phone to access, if it is a mobile phone, jump to the designated mobile phone-friendly page. Here's how to tell if a user is using a mobile phone to access it.

The custom functions are as follows:

$agent=Check_wap ();if($agent ){  Header(' Location:http://www.jb51.net '); Exit;} //Check if WAPfunctionCheck_wap () {//first check whether it is a WAP proxy, high accuracy  if(Stristr($_server[' Http_via '], "WAP")){    return true; }  //Check if the browser accepts WML.  ElseIf(Strpos(Strtoupper($_server[' http_accept ']), "VND. Wap. WML ") > 0){    return true; }  //Check User_agent  ElseIf(Preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera Mini|opera | googlebot-mobile| yahooseeker\/m1a1-r2d2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh| Spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/I ',$_server[' Http_user_agent '])){    return true; }  Else{    return false; }}

Another way to decide whether to peel from the PHP framework is the function of the Mobile Terminal: (tested, very comprehensive, recommended)

functionis_mobile_request () {$_server[' all_http '] =isset($_server[' All_http ']) ?$_server[' All_http ']: '; $mobile _browser= ' 0 '; if(Preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/I ',Strtolower($_server[' Http_user_agent '])))   $mobile _browser++; if((isset($_server[' http_accept '])) and (Strpos(Strtolower($_server[' http_accept ']), ' application/vnd.wap.xhtml+xml ')!==false))   $mobile _browser++; if(isset($_server[' Http_x_wap_profile ']))   $mobile _browser++; if(isset($_server[' Http_profile ']))   $mobile _browser++; $mobile _ua=Strtolower(substr($_server[' Http_user_agent '],0,4)); $mobile _agents=Array(     ' acs-', ' Alav ', ' Alca ', ' amoi ', ' Audi ', ' Avan ', ' BenQ ', ' bird ', ' Blac ', ' Blaz ', ' brew ', ' cell ', ' cldc ', ' cmd-', ' Dang ' , ' doco ', ' Eric ', ' Hipt ', ' Inno ', ' iPAQ ', ' Java ', ' Jigs ', ' kddi ', ' Keji ', ' Leno ', ' lg-c ', ' lg-d ', ' lg-g ', ' lge-', ' Maui ', ' Maxo ', ' MIDP ', ' mits ', ' mmef ', ' mobi ', ' mot-', ' moto ', ' mwbp ', ' nec-', ' Newt ', ' Noki ', ' oper ', ' palm ', ' pana ', ' Pant ', ' Phil ' , ' play ', ' Port ', ' ProX ', ' qwap ', ' sage ', ' Sams ', ' Sany ', ' sch-', ' sec-', ' send ', ' Seri ', ' sgh-', ' shar ', ' sie-', ' Siem ', ' Smal ', ' Smar ', ' Sony ', ' sph-', ' symb ', ' t-mo ', ' Teli ', ' tim-', ' tosh ', ' tsm-', ' upg1 ', ' upsi ', ' vk-v ', ' Voda ', ' wap-', ' Wapa ' , ' Wapi ', ' wapp ', ' wapr ', ' webc ', ' winw ', ' winw ', ' xda ', ' xda-'    ); if(In_array($mobile _ua,$mobile _agents))   $mobile _browser++; if(Strpos(Strtolower($_server[' All_http ']), ' Operamini ')!==false)   $mobile _browser++; //pre-final Check to reset everything if the user are on Windows if(Strpos(Strtolower($_server[' Http_user_agent ']), ' windows ')!==false)   $mobile _browser=0; //but WP7 was also Windows, with a slightly different characteristic if(Strpos(Strtolower($_server[' Http_user_agent ']), ' windows Phone ')!==false)   $mobile _browser++; if($mobile _browser>0)   return true; Else  return false;

PHP website to determine whether a user is a mobile phone access method

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.