Home > Article > Backend Development > PHP development tips to determine whether WeChat access
The content shared with you in this article is PHP development tips for judging whether WeChat access is available. It has a certain reference value. Friends in need can refer to it
Sometimes it is necessary to prohibit or only allow during development If you use WeChat browser to access, then you need to judge whether it is WeChat browser access. This blog post describes how to judge whether it is 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("不是微信浏览器"); } }
Related recommendations:
Judgement of PHP development for WeChat browser access
PHP development high availability and high security app back-end study notes
Some PHP development security issues compiled
The above is the detailed content of PHP development tips to determine whether WeChat access. For more information, please follow other related articles on the PHP Chinese website!