Home > Backend Development > PHP Tutorial > PHP development tips to determine whether WeChat access

PHP development tips to determine whether WeChat access

不言
Release: 2023-03-23 13:52:01
Original
1716 people have browsed it

The content shared with you in this article is PHP development tips for judging whether WeChat access is available. It has a certain reference value. Friends in need can refer to it

Sometimes it is necessary to prohibit or only allow during development If you use WeChat browser to access, then you need to judge whether it is WeChat browser access. This blog post describes how to judge whether it is 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

Related recommendations:

Judgement of PHP development for WeChat browser access

PHP development high availability and high security app back-end study notes

Some PHP development security issues compiled

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

Related labels:
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