How to determine whether mobile browsing or computer browsing

Source: Internet
Author: User
How can I determine whether a browser is a mobile phone browser or a computer browser? do I want to display different pages based on different devices to determine the IP address ??? What are the IP segments of the two ~~~ Or determine the browser type ??? This seems to have too many browsers ~~~ ------ Solution -------------------- there is no absolute way to separate. The following functions are provided. if they are not intentionally obfuscated, the success rate is above 99% ~ Function & nbsp; isMobile () & nbsp
To display different pages based on different devices

Are IP addresses determined ??? What are the IP segments of the two ~~~

Or determine the browser type ??? This seems to have too many browsers ~~~
------ Solution --------------------
There are no absolute methods to separate.
The following functions are provided. if they are not intentionally obfuscated, the success rate is above 99% ~
Function isMobile (){
If (isset ($ _ SERVER ['http _ X_WAP_PROFILE ']) {
Return TRUE;
}

If (isset ($ _ SERVER ['http _ vean']) & stristr ($ _ SERVER ['http _ vean'], "wap ")){
Return TRUE;
}

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 ');
If (preg_match ("/(". implode ('
------ Solution --------------------
', $ Clientkeywords). ")/I", strtolower ($ _ SERVER ['http _ USER_AGENT']) {
Return TRUE;
}
}

If (isset ($ _ SERVER ['http _ ACCEPT ']) {
If (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ')! = False)
& (Strpos ($ _ SERVER ['http _ ACCEPT '], 'text/html') = false

------ Solution --------------------
(Strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml') <strpos ($ _ SERVER ['http _ ACCEPT '], 'text/html ')))){
Return TRUE;
}
}

Return FALSE;
}

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.