PHP to determine whether the user phone access code, PHP judge access Code _php tutorial

Source: Internet
Author: User
Tags php framework

PHP Determines if the user is accessing the code, PHP determines the access code


With the popularity of mobile devices, the site will also usher in more and more mobile device access. Adapt to the PC's page, many times the user is not friendly to the phone, then sometimes we need to determine whether users use mobile phone access, if it is 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.bkjia.com '); exit;} Check if Wapfunction check_wap () {//checks whether it is a WAP proxy, high accuracy if (stristr ($_server[' Http_via '), "WAP")) {   return true;}//Check Check whether 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 function that is stripped from the PHP framework is the cell phone's mobile terminal:

function Is_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 '), ' Windo WS ')!== false) $mobile _browser=0; But WP7 are also Windows, with a slightly different characteristic if (Strpos (strtolower ' $_server['), ' W indows phone ')!== false) $mobile _browser++; if ($mobile _browser>0) return true; else return false; }

To share a personal use of

function Isphone () {///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 if (STRISTR ' H    Ttp_via '], "WAP") {return true;      }}//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 ', ' NetFront ', ' Symbian ', ' UCWeb ', ' windowsce ', ' palm ', ' Operamini ', ' Opera    Mobi ', ' Openwave ', ' nexusone ', ' cldc ', ' MIDP ', ' wap ', ' mobile ', ' phone ', '; 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 that must be mobile device//If WML and HTML are supported but WML Before HTML is the mobile device if ((Strpos ($_server[' http_accept '), ' VND.WAP.WML ')!== false) && (Strpos ($_server[' http_ ACCEPT '], ' text/html ') = = = False | | (Strpos ($_server[' http_accept '), ' vnd.wap.wml ') < Strpos ($_server[' http_accept '], ' text/html '))))    {return true; }} return false;}

The above mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/1013716.html www.bkjia.com true http://www.bkjia.com/PHPjc/1013716.html techarticle PHP Determines whether the user has access to the code, PHP to determine the access code with the popularity of mobile devices, the site will also usher in more and more mobile device access. With the Adaptation PC page, many times ...

  • Related Article

    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.