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:
Copy CodeThe code is as follows:
$agent = Check_wap ();
if ($agent)
{
Header (' location:http://www.nowamagic.net ');
Exit
}
Check if WAP
function Check_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)
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;
http://www.bkjia.com/PHPjc/825022.html www.bkjia.com true http://www.bkjia.com/PHPjc/825022.html techarticle with the popularity of mobile devices, the site will also usher in more and more mobile device access. To adapt to the PC's page, many times the user is not friendly to the mobile phone, then some time, we need to award ...