This article will share with you a function used by php to determine whether to access mobile terminals. it was previously added to the favorites list. it is released here and recommended to our friends. I forgot where I got the function. I just couldn't find it in a package and saved it temporarily.
The code is as follows:
/**
* Mobile access?
*
* @ Return bool
*/
Function isMobile ()
{
// If HTTP_X_WAP_PROFILE exists, 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 providers will block this information.
If (isset ($ _ SERVER ['http _ vean'])
{
// Flase cannot be found; otherwise, true
Return stristr ($ _ SERVER ['http _ vean'], "wap ")? True: false;
}
// Identify the client flag sent by the mobile phone. the 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'
);
// Search for the keyword of the mobile browser from HTTP_USER_AGENT
If (preg_match ("/(". implode ('|', $ clientkeywords). ")/I", strtolower ($ _ SERVER ['http _ USER_AGENT '])
{
Return true;
}
}
// Resolution, which may be inaccurate and placed in 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. I hope you will like them.