When developing WeChat public accounts, a large part of it is the development of micro-sites. We need to know that the current browser is a built-in browser for WeChat. So how do you judge it?
User Agent with built-in browser of WeChat
How to judge the built-in browser of WeChat, first you need to obtain the User Agent of the built-in browser of WeChat. After detection by the WeChat browser on the iPhone, its User Agent is:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1
So by identifying the keyword MicroMessenger, we can determine whether the browser is built-in to WeChat.
Judgement through JavaScript
function is_weixin(){var ua = navigator.userAgent.toLowerCase();if(ua.match(/MicroMessenger/i)=="micromessenger") {return true;} else {return false;}}Judge by PHP
function is_weixin(){ if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {return true;} return false;}