PHP to determine whether the page is a micro-letter open Example (micro-mail open page) _php instance

Source: Internet
Author: User

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,

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.