Sometimes during development, it is necessary to prohibit or only allow access by the WeChat browser. At this time, it is necessary to judge whether the WeChat browser access is. This blog post describes how to judge whether it is a WeChat access.
<?php /** * ======================================= * Created by ZHIHUA·WEI. * Author: ZHIHUA·WEI * Date: 2018/4/10 * Time: 09:20 * Project: PHP开发小技巧 * Power: 判断是否微信访问 * ======================================= */ /** * 判断是否微信访问 * @return bool */ function is_weixin_visit() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { return true; } else { return false; } } if(is_weixin_visit()){ echo "微信访问!"; }else{ echo "other"; }
Note (introducing one more js method):
function is_weixin() { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { console.log("微信浏览器"); } else { console.log("不是微信浏览器"); } }
The above is the detailed content of PHP development to determine WeChat browser access. For more information, please follow other related articles on the PHP Chinese website!