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

PHP development to determine WeChat browser access

零到壹度
Release: 2023-03-23 13:34:02
Original
4524 people have browsed it

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";
}
Copy after login


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("不是微信浏览器"); 
    } 
}
Copy after login


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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template