Home >Backend Development >PHP Tutorial >PHP determines whether WeChat is opened or the browser is opened

PHP determines whether WeChat is opened or the browser is opened

php中世界最好的语言
php中世界最好的语言Original
2018-03-24 09:20:464042browse

This time I will bring you PHPJudge whether WeChat is opened or the browser is opened, PHP determines whether WeChat is opened or the browser is openedWhat are the precautions, the following is a practical case , let’s take a look.

#Problem

Problems encountered in the project, if the user accesses using WeChat.

Then make it friendly Tips"How to open with a browser/Tell the user to open with a browser"

Solution

useragent is the browser identifier, with some customer information. For example, the browser kernel, operating system, etc.

WeChat access to the web page is also a browser, and it also has a UA. Then you can identify it by judging its UA. Whether it has been visited by WeChat

$ua = $_SERVER['HTTP_USER_AGENT']; 
//MicroMessenger 是android/iphone版微信所带的
//Windows Phone 是winphone版微信带的 (这个标识会误伤winphone普通浏览器的访问)
if(strpos($ua, 'MicroMessenger') == false || strpos($ua, 'Windows Phone') == false){ 
 echo "来自普通浏览器访问"; 
}else{ 
 echo "来自微信浏览器访问"; 
}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Mysqld_multi deployment stand-alone detailed explanation

Summary of some MySQL traps

The reason why the installation of mysql service failed to start

How to operate the table in Bootstrap

The above is the detailed content of PHP determines whether WeChat is opened or the browser is opened. 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