


WeChat public platform message interface development (31) WeChat browser HTTP_USER_AGENT judgment_PHP tutorial
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>?>
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
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
, 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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The top ten virtual currency trading apps in 2025 are as follows: 1. OKX, 2. Binance, 3. Gate.io, 4. Bybit, 5. Kraken, 6. KuCoin, 7. Bitget, 8. HTX, 9. MEXC, 10. Coinbase. This ranking is based on comprehensive evaluations such as security, liquidity, user experience and feature richness.

The top ten digital virtual currency trading apps in 2025 are as follows: 1. OKX, 2. Binance, 3. Gate.io, 4. Bybit, 5. Kraken, 6. KuCoin, 7. Bitget, 8. HTX, 9. MEXC, 10. Coinbase. This ranking is based on comprehensive evaluations such as security, liquidity, user experience and feature richness.

Solve the problem of third-party interface returning 403 in Node.js environment. When we use Node.js to call third-party interfaces, we sometimes encounter an error of 403 from the interface returning 403...

Ouyi usually refers to Ouyi OKX. The global way to download Ouyi OKX APP is as follows: 1. Android device: Download the APK file through the official website and install it. 2. iOS device: access the official website through the browser and directly download the APP.

This article provides a detailed Gate.io registration tutorial, covering every step from accessing the official website to completing registration, including filling in registration information, verifying, reading user agreements, etc. The article also emphasizes security measures after successful registration, such as setting up secondary verification and completing real-name authentication, and gives tips from beginners to help users safely start their digital asset trading journey.

The top ten virtual currency trading apps in 2025 are as follows: 1. OKX, 2. Binance, 3. Gate.io, 4. Bybit, 5. Kraken, 6. KuCoin, 7. Bitget, 8. HTX, 9. MEXC, 10. Coinbase. This ranking is based on comprehensive evaluations such as security, liquidity, user experience and feature richness.

Want to use the Chinese interface on Binance? This article teaches you how to handle it easily! Whether it is the web or the app, you can set the language to Simplified Chinese or Traditional Chinese in just a few simple steps, saying goodbye to the troubles of English and enjoy a smoother and more convenient transaction experience.

This article provides a detailed Gate.io web version latest registration tutorial to help users easily get started with digital asset trading. The tutorial covers every step from accessing the official website to completing registration, and emphasizes security settings after registration. The article also briefly introduces other trading platforms such as Binance, Ouyi and Sesame Open Door. It is recommended that users choose the right platform according to their own needs and pay attention to investment risks.
