


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

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

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



H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

The main difference between an abstract class and an interface is that an abstract class can contain the implementation of a method, while an interface can only define the signature of a method. 1. Abstract class is defined using abstract keyword, which can contain abstract and concrete methods, suitable for providing default implementations and shared code. 2. The interface is defined using the interface keyword, which only contains method signatures, which is suitable for defining behavioral norms and multiple inheritance.

Discussion on using custom stylesheets in Safari Today we will discuss a custom stylesheet application problem for Safari browser. Front-end novice...

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

How to use JavaScript or CSS to control the top and end of the page in the browser's printing settings. In the browser's printing settings, there is an option to control whether the display is...

The choice of H5 and applet depends on the requirements. For applications with cross-platform, rapid development and high scalability, choose H5; for applications with native experience, rich functions and platform dependencies, choose applets.

H5 is more flexible and customizable, but requires skilled technology; mini programs are quick to get started and easy to maintain, but are limited by the WeChat framework.

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...
