This article by the code Farm-small peak original, reproduced please see the text at the end of the reprint requirements, welcome to participate in our paid contribution program!
Today to share a PHP code, the function of the code is to determine whether the visitor mobile browser access, the implementation of the idea is through Http_x_wap_profile, Http_via, Http_user_ Agent and other information to determine if a visitor is accessing a PHP website via a mobile browser. Here's the PHP code:
/** * Whether mobile Access access * * @return bool */function ismobile () {//If there is http_x_wap_profile it must be a mobile device if (Isset ($_server[' http_ X_wap_profile ']) {return true; }//If the VIA information contains WAP it must be a mobile device, some service associations block the information if (Isset ($_server[' Http_via ')) {//Cannot find for flase, otherwise true re Turn stristr ($_server[' Http_via '), "WAP")? True:false; }//Brain residue method, determine the mobile phone sent by the client flag, compatibility needs to be improved if (Isset ($_server[' http_user_agent ')) {$clientkeywords = array (' Nokia ' , ' Sony ', ' Ericsson ', ' mot ', ' Samsung ', ' HTC ', ' SGH ', ' LG ', ' sharp ', ' sie-', ' Philips ', ' Panasonic ', ' Alcatel ', ' Lenovo ', ' iphone ', ' ipod ', ' blackberry ', ' Meizu ', ' Android OID ', ' NetFront ', ' Symbian ', ' UCWeb ', ' windowsce ', ' palm ', ' Operamini ', ' Operamobi ', ' Openwave ', ' nexusone ', ' cldc ', ' MIDP ', ' wap ', ' mobile ' ); Look for the keyword if (Preg_match ("/(") of the phone's browser from Http_user_agent. Implode (' | ', $clientkeywords). ")/I", Strtolower ($_server[' http_user_agent '))) {return true; }}//protocol method, because it may not be accurate, put to the Last Judgment if (Isset ($_server[' http_accept ')) {//If only WML is supported and HTML is not supported it must be a mobile device. If WML and HTML are supported but WML is before HTML the mobile device if ((Strpos ($_server[' http_accept '), ' VND.WAP.WML ')!== false) && (STRP OS ($_server[' http_accept '), ' text/html ') = = = False | | (Strpos ($_server[' http_accept '), ' vnd.wap.wml ') < Strpos ($_server[' http_accept '], ' text/html ')))) {return true; }} return false;}
The code is more complete, interested students can do more tests, there are any bug can comment in the comments.
The above describes PHP to determine whether a visitor mobile browser access, including PHP, browser content, I hope to be interested in PHP tutorial friends helpful.