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

Source: Internet
Author: User
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.

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.