PHP and JavaScript are used to determine whether the request is from a WeChat browser. php?cript_php tutorial

Source: Internet
Author: User
Use PHP and JavaScript to determine whether the request comes from an internal browser or phpjavascript. Use PHP and JavaScript to determine whether the request comes from an internal browser. if the HTTP_USER_AGENT of the phpjavascript browser is under the iPhone, return Mozilla5.0 (iPhone; CPUiPhoneOS5_1like using PHP and JavaScript to determine whether the request comes from an internal browser, phpjavascript

HTTP_USER_AGENT of the browser

Under the iPhone, return

Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2)

In Android

Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255)

It is not difficult to find that the browser is MicroMessenger and has a version number. you can also determine whether the mobile phone type is iPhone or Android.

If you want to perform leeching

If (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "MicroMessenger") echo "Welcome to wechat word"; else echo "http/1.1 401 Unauthorized "; public function is_weixin () {if (strpos ($ _ SERVER ['http _ USER_AGENT '], 'micromessenger ')! = False) {return true;} return false;} if ($ this-> is_weixin () {} else {echo "please visit this website. ";}

Js judgment
function is_weixin(){  var ua = navigator.userAgent.toLowerCase();  if(ua.match(/MicroMessenger/i)=="micromessenger") {    return true;   } else {    return false;  }}

After the browser is determined on the mobile phone end, you can use the share js script to process it. for details, refer to the official document. here is a case study to learn about the general process and ideas.

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.