Home > Article > Backend Development > The root cause of the garbled page problem and its analysis_PHP tutorial
First, turn off the default_charset in the PHP configuration file php.ini:
1. The page does not specify charset, Apache configures defaultcharst gbk, and the page file encoding is utf-8
Result: Garbled code, use wireshark to capture the packet, and find that the header returned by the server specifies:
2. The specified charset of the page is utf-8, and Apache configures defaultcharset gbk. The page file is utf-8
Copy code
Read the Apache2 manual:
AddDefaultCharset directive explains that when the response content is text/plain or text/html, add it to the HTTP response header Default Charset
Syntax AddDefaultCharsetOn|Off|charsetDefault AddDefaultCharsetOffScope serverconfig, virtualhost,directory,.htaccess
Override FileInfo
State Core (C)
Module core
If and only if the response content is text/plain or text/html, this directive will add the
default character set in the HTTP response header. Theoretically this will override the character set specified via the tag in the document body, but the actual behavior of
usually depends on the user's browser settings. AddDefaultCharsetOff will disable this feature.
AddDefaultCharsetOn will enable the default character set within Apache, iso-8859-1. You
can also specify to use another charset from one of the character set names registered with IANA.
For example:
AddDefaultCharsetutf-8
In other words, when Apache does not specify defaultcharset, the page encoding is specified by the page's own meta tag.
When specified by Apache, the encoding specified by the meta tag in the page will be ignored. However, the script is allowed to directly encode the header to the client
What if neither Apache nor the page are specified?
I am on my own machine. If I don’t specify anything, the default is still utf8.
www.bkjia.com