Use PHP and JavaScript to determine if the request came from a _php instance of a micro-mail browser

Source: Internet
Author: User

Http_user_agent of micro-mail browser

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, return

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)

It's not hard to find a Micromessenger browser with a version number, or a phone type of iphone or Android.

If you want to do hotlinking

if (Strpos ($_server["Http_user_agent"], "Micromessenger"))
  echo "Welcome to WeChat word";
else
  echo "http/1.1 401 Unauthorized";

Public Function Is_weixin () { 
if (Strpos ($_server[' http_user_agent '), ' Micromessenger ')!== false)
 true;
}
 return false;
}    
if ($this->is_weixin ()) {
 }else{
 echo "Please visit this website using micro-letters. ";
} 


JS Judgment
function Is_weixin () {
  var ua = Navigator.userAgent.toLowerCase ();
  if (Ua.match (/micromessenger/i) = = "Micromessenger") {return
    true;
   } else {return
    false
  ;
}}

When the phone to judge the micro-mail browser, you can use the micro-letter to share the JS script to deal with it, you can refer to the micro-letter official documents, here provides a case, understand the next general flow and ideas

<script type= "Text/javascript" src= "/jslib/wx_share.js" ></script> <script>//share links to rewrite the share title, indent
      Sketch, link, profile, etc. var imgurl = ' <?php echo base_url ('/images/per.png ');?> ';
      var linelink = ' http://www.baidu.com/';
      var sharetitle = ' I'll send you the money '; var desccontent = ' Refractive index, do you know what it is?
      ';
      var timeline_title = ' Timeline_title ';
    var appid = ';
      </script> <script> function Onbridgeready () {weixinjsbridge.call (' showoptionmenu '); } </script> <script> if (typeof Weixinjsbridge = = "undefined") {if (Document.addeventli
        Stener) {document.addeventlistener (' Weixinjsbridgeready ', Onbridgeready, false);
          else if (document.attachevent) {document.attachevent (' Weixinjsbridgeready ', onbridgeready);
        Document.attachevent (' Onweixinjsbridgeready ', onbridgeready);
      } else {onbridgeready (); } </script> 

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.