An example of PHP’s method to determine whether wechat access is possible


The example of this article describes PHP’s method to determine whether wechat access is possible. To share with you for your reference, as follows:

Sometimes it is necessary to prohibit or only allow wechat browser access in development, so wechat browser access needs to be judged at this time. This post describes how to determine whether wechat access is.

 * ======================================= 
 * Created by ZHIHUA·WEI. 
 * Author: ZHIHUA·WEI 
 * Date: 2018/4/10 
 * Time: 09:20 
 *Project: PHP development tips 
 *Power: determine whether wechat access is available
 * ======================================= 
 *Judge whether to visit WeChat
 * @return bool
function is_weixin_visit()
  if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
    return true;
  } else {
    return false;
 Echo "wechat access! ";
 echo "other";

Note (more about a JS method):

function is_weixin() { 
  var ua = window.navigator.userAgent.toLowerCase(); 
  if (ua.match(/MicroMessenger/i) == 'micromessenger') { 
    Console.log ("wechat browser"); 
  } else { 
    Console.log ("not wechat browser"); 

PS: Here we recommend 2 browser judgment online tools with similar functions for your reference:

Online browser information detection tool:

Common browser (PC, mobile) user agent:

For more information about PHP, please refer to the following topics: summary of PHP network programming skills, summary of PHP regular expression usage, and PHP Curl usage summary, PHP array operation skill collection, PHP string usage summary, PHP data structure and algorithm tutorial, PHP programming algorithm summary, PHP mathematical operation skill summary and PHP common database operation skill summary

I hope that this article will be helpful for PHP programming.