PHP method: Use the "_ SERVER" array "HTTP_USER_AGENT" of PHP to obtain the information of the user agent on the page to complete this work.
| The code is as follows: |
Copy code |
|
<? Php
Echo $ _ SERVER ["HTTP_USER_AGENT"];
?> |
[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
And [ios7/weixin]
Output result:
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 character string shows that "MicroMessenger" is the WeChat browser version, so you can use the "MicroMessenger" parameter to determine whether the access source is "WeChat browser ".
| The code is as follows: |
Copy code |
|
If (strpos ($ _ SERVER ['http _ USER_AGENT '], "MicroMessenger "))
{
Echo "Hello Weixin ";
}
Javascript method:
Function isweixin (){
Var ua = navigator. userAgent. toLowerCase ();
If (ua. match (/MicroMessenger/I) = "micromessenger "){
Return true;
} Else {
Return false;
}
} |