Home  >  Article  >  Backend Development  >  PHP development to determine WeChat browser access

PHP development to determine WeChat browser access

零到壹度
零到壹度Original
2018-04-10 11:22:324487browse

Sometimes during development, it is necessary to prohibit or only allow access by the WeChat browser. At this time, it is necessary to judge whether the WeChat browser access is. This blog post describes how to judge whether it is a WeChat access.

<?php

/** 
 * ======================================= 
 * Created by ZHIHUA·WEI. 
 * Author: ZHIHUA·WEI 
 * Date: 2018/4/10 
 * Time: 09:20 
 * Project: PHP开发小技巧 
 * Power: 判断是否微信访问
 * ======================================= 
 */  

/**
 * 判断是否微信访问
 * @return bool
 */
function is_weixin_visit()
{
    if (strpos($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;MicroMessenger&#39;) !== false) {
        return true;
    } else {
        return false;
    }
}


if(is_weixin_visit()){
	echo "微信访问!";
}else{
	echo "other";
}


Note (introducing one more js method):


function is_weixin() { 
    var ua = window.navigator.userAgent.toLowerCase(); 
    if (ua.match(/MicroMessenger/i) == &#39;micromessenger&#39;) { 
        console.log("微信浏览器"); 
    } else { 
        console.log("不是微信浏览器"); 
    } 
}


The above is the detailed content of PHP development to determine WeChat browser access. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn