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
http://www.bkjia.com/PHPjc/440338.htmlwww.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...