Copy Code code as follows:
$user _agent = $_server[' http_user_agent '];
if (Strpos ($user _agent, ' micromessenger ') = = False) {
Non-micro browser prohibit browsing
echo "http/1.1 401 Unauthorized";
} else {
Micro-mail browser, allow access
echo "Micromessenger";
Get version number
Preg_match ('/.*? micromessenger\/([0-9.] +)) \s*/', $user _agent, $matches);
Echo ' <br>version: '. $matches [2];
}
Well, I can't just refute it, but it's really, really unreliable,
Get the data and talk.
The following are the http_user_agent messages for Android, Winphone, and IPhone.
Copy Code code as follows:
"Http_user_agent": "mozilla/5.0" (Linux; U Android 4.1; ZH-CN; Galaxy Nexus build/wind-galaxy nexus-v1.2) applewebkit/534.30 (khtml, like Gecko) version/4.0 Mobile safari/534.30 Microm essenger/5.0.1.352 ",
"Http_user_agent": "mozilla/5.0" (compatible; MSIE 10.0; Windows Phone 8.0; trident/6.0; iemobile/10.0; ARM; Touch; NOKIA; Nokia 920T) ",
"Http_user_agent": "mozilla/5.0" (IPhone; CPU iPhone os 6_1_3 like Mac os X) applewebkit/536.26 (khtml, like Gecko) mobile/10b329 micromessenger/5.0.1 ",
Can see Winphone there is no micromessenger so can not judge, in fact, useragent judge is very fake things, so I think should use JS to determine whether there is Weixinjsbridge, and then Ajax to PHP
PHP detected and then returned to the real page information, period plus a "desperate load ..." This is very harmonious, of course, Ajax words, but also can deceive, but relatively useragent deception, it will be a little trouble,
But our goal is to detect whether it is a micro-client, not the problem of deception, the specific code I do not write, because the most annoying kind of copycat, unlimited copy sticky, and sometimes the code is filtered part of the no matter,