PHP is how to determine the mobile phone, computer access to automatically skip the file

Source: Internet
Author: User

PHP to determine the mobile phone computer access automatic jumping head file code as follows:

<?php  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&nbsp= array (        ' w3c  ', ' 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 is on Windows    if (Strpos strtolower ($_server[' http_user_agent '),   ' windows ')  !== false       $mobile _browser=0;    // but  wp7 is 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; }      if (is_mobile_requesT ()) {  header ("location:app/index.html"), Exit (),} else{  header ("location:index/index.html"), exit ();  }?>

The above is PHP to determine the mobile phone computer access to automatically jump the file code, the need for small partners, can be modified according to the actual needs.

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.