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

Time:2020-5-18

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.

<?php
/** 
 * ======================================= 
 * 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;
  }
}
if(is_weixin_visit()){
 Echo "wechat access! ";
}else{
 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:
http://tools.jb51.net/aideddesign/browser_info

Common browser (PC, mobile) user agent:
http://tools.jb51.net/table/useragent

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.