search
HomeBackend DevelopmentPHP TutorialWeChat 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
agenthttpuserjudgmentplatformdevelopDeveloperWeChatinterfacemodelBrowserinformation

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>?>
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
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
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
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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 Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.