PHP _php Tutorial To determine whether a function code is a mobile terminal for mobile phone through http_user_agent

Source: Internet
Author: User
Sometimes it's practical. On some occasions, keep the spare.

Copy CodeThe code is as follows:
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 (
' The ' 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;
}

Article Source: http://yi1.com.cn/posts/781

PHP determines user browser type based on Http_user_agent
Copy the Code code as follows:
function browsers () {
Global $HTTP _user_agent;
if (Isset ($HTTP _user_agent)) {
$sAgent = $HTTP _user_agent;
}else{
$sAgent = $_server[' http_user_agent ');
}
if (Strpos ($sAgent, ' MSIE ')!== false && Strpos ($sAgent, ' mac ') = = = False && Strpos ($sAgent, ' Opera ') = = = FA LSE) {
$iVersion = (float) substr ($sAgent, Strpos ($sAgent, ' MSIE ') + 5,3);
Return ($iVersion >= 5.5);
}else if (Strpos ($sAgent, ' gecko/')!== false) {
$iVersion = (int) substr ($sAgent, Strpos ($sAgent, ' gecko/') + 6,8);
Return ($iVersion >= 20030210);
}else{
return false;
}
}

http://www.bkjia.com/PHPjc/326626.html www.bkjia.com true http://www.bkjia.com/PHPjc/326626.html techarticle sometimes it's practical. On some occasions, keep the backup copy code code is as follows: function Is_mobile_request () {$_server[' all_http '] = isset ($_server[' all_http ')? $_ server[' All_htt ...

  • 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.