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