Php determines whether the user's browser type is WeChat browser

Source: Internet
Author: User

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;
    }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.