Root cause and analysis of page garbled text. First, close the PHP configuration file php. default_charset in ini: 1. charset is not specified on the page, defaultcharstgbk is configured in Apache, and the page file encoding is UTF-8 result: Garbled. use wiresh to first close the PHP configuration file php. default_charset in ini:
1. charset is not specified on the page. Apache configures defaultcharst gbk and the page file encoding is UTF-8.
Result: garbled characters are captured using wireshark. the header returned by the server indicates:
The code is as follows:
Content-Type: text/html; charset = GB
Conclusion: Apache defaultcharset takes effect when charset is not specified on the page.
2. set charset to UTF-8 on the page, and configure defaultcharset gbk in Apache. the page file is UTF-8.
The code is as follows:
Test Apache DefaultCharset
The result is garbled.
Conclusion: when DefaultCharset is configured for Apache, the charset statement of the page is ignored.
3. PHP header declares charset as utf8, Apache configures defaultcharst gbk, and the page file encoding is utf8
The code is as follows:
Header ("Content-Type: text/html; charset = utf-8 ");
Result: The page is displayed normally.
4. set DefaultCharset off in Apache
Result: The page is displayed normally.
Read the Apache2 manual:
Adddefacharcharset command
Indicates the default character set added to the HTTP response header when the response content is text/plain or text/html.
Syntax adddefacharcharseton | Off | charset
Default value: adddefacharcharsetoff
Scope: serverconfig, virtualhost, directory,. htaccess
Overwrite FileInfo
Status core (C)
Module core
This command is added to the HTTP response header only when the response content is text/plain or text/html.
Default character set. Theoretically, this will cover The character set specified by the tag, but the actual
Usually depends on the user's browser settings. Adddefacharcharsetoff will disable this function.
Adddefacharcharseton enables the default character set ISO-8859-1 within Apache. You
You can also specify another charset in the character set name registered in IANA.
For example:
AddDefaultCharsetutf-8
That is, when defaultcharset is not specified for Apache, the page encoding is specified by the meta tag of the page.
When Apache is specified, the encoding specified by the meta tag on the page is ignored, but the script can be directly used as the header encoding method to the client.
Finally, there is another problem that has not been returned:
What if Apache and the page are not specified?
If none of my machines are specified, the default value is utf8.
Disable: disable default_charset: 1 in PHP configuration file php. ini. the charset is not specified on the page. Apache configures defacharcharst gbk. the page file is encoded as UTF-8 and garbled. wiresh is used...