PHP function implementation to determine whether to move the end access _php tips

Source: Internet
Author: User

Forget where to get the function, just don't mind in a bag inside find, temporarily saved up

Copy Code code as follows:

/**
* Whether to move end access access
*
* @return BOOL
*/
function IsMobile ()
{
If you have http_x_wap_profile, you 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, and some service providers block the information
if (Isset ($_server[' Http_via '))
{
Not found for flase, otherwise true
Return Stristr ($_server[' Http_via '], "WAP")? True:false;
}
Brain residue method, to judge the mobile phone to send the client logo, 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 ',
' Operamobi ',
' Openwave ',
' Nexusone ',
' CLDC ',
' MIDP ',
' WAP ',
' Mobile '
);
Find keywords for mobile browsers from Http_user_agent
if (Preg_match) ("/". Implode (' | ', $clientkeywords). ")/I", Strtolower ($_server[' http_user_agent ')))
{
return true;
}
}
Agreement law because there may be inaccurate and put it to the final 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 a mobile device before HTML
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;
}

Very simple and practical functions, to share with everyone, I hope you can enjoy.

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.