To determine the user's browser type, we only need to use $ _ SERVER [quot; HTTP_USER_AGENTquot;] in php to obtain the data, but the obtained data is very raw, to determine the type, we need to add a segment of st... to determine the browser type of a user, we only need to use $ _ SERVER ["HTTP_USER_AGENT"] in php to obtain the data, but the obtained data is very primitive, to determine the type, add strpos ($ _ SERVER ['http _ USER_AGENT '] and "MicroMessenger". the specific steps are as follows.
PHP method: Use the "_ SERVER" array "HTTP_USER_AGENT" item of PHP to obtain the information of the user agent on the page to complete this task. the code is as follows:
Winows/chrome output result:
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36
The output result in ios7/weixin is as follows:
Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B554a MicroMessenger/5.0.3
The string shows that "MicroMessenger" is the browser version, so you can use the "MicroMessenger" parameter to determine whether the access source is "browser". the code is as follows:
if(strpos($_SERVER['HTTP_USER_AGENT'],"MicroMessenger ")) { echo "Hello Weixin";//phprm.com}
The Javascript method code is as follows:
function isweixin(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { return true; } else { return false; } }
Tutorial URL:
You are welcome to add your _ favorites to the Favorites folder, but please keep the link for this article.