Identify browser information to determine if Android or iphone

Source: Internet
Author: User

In PHP http_user_agent is used to obtain information about the user, including the user's browser, operating system and other information,

In the development of the public platform, we sometimes need to develop the Web page and determine whether it is from the browser access, this article describes how to make this decision.

One, $_server array

$_SERVERis an array of information such as header information (header), path, and script location (scripts locations), and so on. The items in this array are created by the WEB server. There is no guarantee that each server will provide all of the items, and the server may ignore some.

Ii. acquisition of Http_user_agent

The following methods can be obtained

<?phpecho $_server["Http_user_agent"];? >

Under the iphone, return

mozilla/5.0 (IPhone; CPU iPhone os 5_1 like Mac os X applewebkit/534.46 (khtml, like Gecko) mobile/9b176 micromessenger/4.3.2

Under Android, go back

mozilla/5.0 (Linux; U Android 2.3.6; ZH-CN; gt-s5660 build/gingerbread) applewebkit/533.1 (khtml, like Gecko) version/4.0 Mobile safari/533.1 micromessenger/ 4.5.255

As you can see, the browser is Micromessenger , followed by its version number
At the same time, you can also determine whether the phone type is iphone or Android

Third, Judge browser access

We judge whether there are micromessenger in Http_user_agent

if (Strpos ($_server["Http_user_agent"], "Micromessenger")) {

echo "Yes";

}else{

echo "No";

}

Identify browser information to determine if Android or iphone

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.