Home Backend Development PHP Tutorial WeChat public platform message interface development (31) WeChat browser HTTP_USER_AGENT judgment_PHP tutorial

WeChat public platform message interface development (31) WeChat browser HTTP_USER_AGENT judgment_PHP tutorial

Jul 20, 2016 am 11:13 AM
agent http user judgment platform develop Developer WeChat interface model Browser information

WeChat public platform development WeChat public platform developer WeChat public platform development model WeChat browser HTTP_USER_AGENT
Author: Fangbei Studio
Original text:http://www.cnblogs.com/txw1958/archive/2013/05/25/weixin-if31-http_user_agent.html

During the development process of the WeChat public platform, we sometimes need to develop a web page and determine whether it is accessed from the WeChat browser. This article introduces how to make this determination.

1. $_SERVER array

$_SERVER is an array containing information such as header, path, and script locations. The items in this array are created by the web server. There is no guarantee that every server will offer all items; servers may ignore some, or serve items not listed here.

In $_SERVER you may or may not be able to find the following elements. Note that few of the elements listed below are valid (or have no practical meaning) if you run PHP from the command line.

'PHP_SELF'
The file name of the currently executing script, related to the document root. For example, using $_SERVER['PHP_SELF'] in a script at http://example.com/test.php/foo.bar will Get /test.php/foo.bar. The __FILE__ constant contains the full path and file name of the current (i.e. containing) file. Starting with PHP version 4.3.0, this variable will contain the script name if PHP is running in command line mode. This variable is not available in previous versions.
'argv'
An array of arguments passed to this script. When the script is run from the command line, the argv variable is passed to the program as C-style command-line arguments. When called via GET, this variable contains the query string.
'argc'
Contains the number of arguments passed to this script in command line mode (if running in command line mode).
'GATEWAY_INTERFACE'
The version of the CGI specification used by the server; for example, " CGI/1.1".
'SERVER_ADDR'
The IP address of the server where the script is currently running.
'SERVER_NAME'
The hostname of the server where the script is currently running. If the script is running on a virtual host, the name is determined by the value set for that virtual host.
'SERVER_SOFTWARE'
Server identification string, header when responding to a request given in the message.
'SERVER_PROTOCOL'
The name and version of the communication protocol when requesting the page. For example, "HTTP/1.0".
'REQUEST_METHOD'
The request method used to access the page; for example, "GET", "HEAD", "POST", "PUT"
' REQUEST_TIME'
The timestamp when the request started. Available since PHP 5.1.0.
'REQUEST_TIME_FLOAT'
Time stamp at the start of the request, microsecond level Accuracy. Effective since PHP 5.4.0.
'QUERY_STRING'
query string (query string), if any Then, access the page through it.
'DOCUMENT_ROOT'
The document root directory where the currently running script is located. Defined in the server configuration file.
'HTTP_ACCEPT'
In the current request header Accept: The contents of the item, if present.
'HTTP_ACCEPT_CHARSET'
In the current request header Accept-Charset: The content of the item, if present. For example: "iso-8859-1,*,utf-8".
'HTTP_ACCEPT_ENCODING'
In the current request header Accept-Encoding: The content of the item, if present. For example: "gzip".
'HTTP_ACCEPT_LANGUAGE'
In the current request header Accept-Language: The content of the item, if present. For example: "en".
'HTTP_CONNECTION'
In the current request header Connection: The contents of the item, if present. For example: "Keep-Alive".
'HTTP_HOST'
In the current request header Host: The contents of the item, if present.
'HTTP_REFERER'
Directs the user agent to the previous page of the current page address (if present). Determined by user agent settings. Not all user agents will set this item, and some also provide the function of modifying HTTP_REFERER. In short, the value is not trustworthy.
'HTTP_USER_AGENT'
In the current request header User-Agent: The content of the item, if present. This string indicates information about the user agent accessing this page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
'HTTPS'
If the script is accessed via HTTPS protocol, it is Set to a non-null value.
'REMOTE_ADDR'
The IP address of the user browsing the current page.
'REMOTE_HOST'
The host name of the user browsing the current page. DNS reverse resolution does not depend on the user's REMOTE_ADDR.
'REMOTE_PORT'
The port used by the user machine to connect to the web server Number.
'REMOTE_USER'
Verified User
'REDIRECT_REMOTE_USER'
Authenticated user if the request has been redirected internally.
'SCRIPT_FILENAME'

The absolute path of the currently executing script

'SERVER_ADMIN'
This value specifies the SERVER_ADMIN parameter in the Apache server configuration file. If the script is running on a virtual host, this value is that of that virtual host.
'SERVER_PORT'
The port used by the web server. The default value is "80". If using SSL secure connection, this value is the HTTP port set by the user.
'SERVER_SIGNATURE'
A string containing the server version and virtual host name .
'PATH_TRANSLATED'
The file system where the current script is located (not the document root directory) base path. This is the result after the server has been imaged from a virtual to real path.
'SCRIPT_NAME'
Contains the path to the current script. This is useful when the page needs to point to itself. The __FILE__ constant contains the full path and file name of the current script (i.e. include file).
'REQUEST_URI'
URI is used to specify the page to be accessed. For example "/index.html".
'PHP_AUTH_DIGEST'
When running as an Apache module, perform HTTP Digest authentication During the process, this variable is set to the "Authorization" HTTP header content sent by the client (for further authentication operations).
'PHP_AUTH_USER'
When PHP is running on Apache or IIS (PHP 5 is ISAPI) module mode, and the HTTP authentication function is being used, this variable is the user name entered by the user.
'PHP_AUTH_PW'
When PHP is running on Apache or IIS (PHP 5 is ISAPI) module mode, and the HTTP authentication function is being used, this variable is the password entered by the user.
'AUTH_TYPE'
When PHP is running in Apache module mode and is Using the HTTP authentication function, this variable is the type of authentication.
'PATH_INFO'
contains the client-supplied, followed by the real script The path information after the name and before the query string, if present. For example, if the current script is accessed through the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER[ 'PATH_INFO'] will contain /some/stuff.
'ORIG_PATH_INFO'
Before being processed by PHP, "PATH_INFO”.

2. Get HTTP_USER_AGENT

The following methods can be obtained

<?<span php
</span><span echo</span> <span $_SERVER</span>["HTTP_USER_AGENT"<span ];
</span>?>
Copy after login
On iPhone, return

Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 <span MicroMessenger</span>/4.3.2
Copy after login
Under Android, return

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 <span MicroMessenger</span>/4.5.255
Copy after login
You can see that the WeChat browser is

, followed by its version number At the same time, you can also determine whether the phone type is iPhone or Android

3. Determine WeChat browser access

We can determine whether there is a MicroMessenger in HTTP_USER_AGENT

================================================== ==============

Welcome to follow

Fangbei Studio on WeChat to learn about the latest developments about us and the industry

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440338.htmlTechArticleWeChat public platform development WeChat public platform developer WeChat public platform development model WeChat browser HTTP_USER_AGENT Author: Fangbei Studio Original text: http://www.cnblogs.com/txw195...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
How to register an account on Ouyi Exchange Ouyi Exchange Registration Tutorial How to register an account on Ouyi Exchange Ouyi Exchange Registration Tutorial Apr 24, 2025 pm 02:06 PM

The steps to register an Ouyi account are as follows: 1. Prepare a valid email or mobile phone number and stabilize the network. 2. Visit Ouyi’s official website. 3. Enter the registration page. 4. Select email or mobile phone number to register and fill in the information. 5. Obtain and fill in the verification code. 6. Agree to the user agreement. 7. Complete registration and log in, carry out KYC and set up security measures.

Download the official website of Ouyi Exchange app for Apple mobile phone Download the official website of Ouyi Exchange app for Apple mobile phone Apr 28, 2025 pm 06:57 PM

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

gate.io sesame door latest official app address gate.io sesame door latest official app address Apr 22, 2025 pm 01:03 PM

The official Gate.io APP can be downloaded in the following ways: 1. Visit the official website gate.io to download; 2. Search "Gate.io" on the App Store or Google Play to download. Be sure to download it through the official channel to ensure safety.

Binance download link Binance download path Binance download link Binance download path Apr 24, 2025 pm 02:12 PM

To safely download the Binance APP, you need to go through the official channels: 1. Visit the Binance official website, 2. Find and click the APP download portal, 3. Choose to scan the QR code, app store, or directly download the APK file to download to ensure that the link and developer information are authentic, and enable two-factor verification to protect the security of the account.

Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Apr 28, 2025 pm 07:51 PM

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Ouyi official website entrance Ouyi official latest entrance 2025 Ouyi official website entrance Ouyi official latest entrance 2025 Apr 28, 2025 pm 07:48 PM

Choose a reliable trading platform such as OKEx to ensure access to the official entrance.

How to register an account on Sesame Open Exchange? Tutorial on Registration of Sesame Open Exchange How to register an account on Sesame Open Exchange? Tutorial on Registration of Sesame Open Exchange Apr 24, 2025 pm 02:00 PM

Registering a Sesame Door Account requires 7 steps: 1. Prepare a valid email or mobile phone number and a stable network; 2. Visit the official website; 3. Enter the registration page; 4. Select and fill in the registration method; 5. Obtain and fill in the verification code; 6. Agree to the user agreement; 7. Complete registration and log in, it is recommended to carry out KYC and set security measures.

Recommended top 10 for easy access to digital currency trading apps (latest ranking in 25) Recommended top 10 for easy access to digital currency trading apps (latest ranking in 25) Apr 22, 2025 am 07:45 AM

The core advantage of gate.io (global version) is that the interface is minimalist, supports Chinese, and the fiat currency trading process is intuitive; Binance (simplified version) has the highest global trading volume, and the simple version model only retains spot trading; OKX (Hong Kong version) has the simple version of the interface is simple, supports Cantonese/Mandarin, and has a low threshold for derivative trading; Huobi Global Station (Hong Kong version) has the core advantage of being an old exchange, launches a meta-universe trading terminal; KuCoin (Chinese Community Edition) has the core advantage of supporting 800 currencies, and the interface adopts WeChat interaction; Kraken (Hong Kong version) has the core advantage of being an old American exchange, holding a Hong Kong SVF license, and the interface is simple; HashKey Exchange (Hong Kong licensed) has the core advantage of being a well-known licensed exchange in Hong Kong, supporting France

See all articles