After change to new software stack, Chinese pages require setting encoding in browser

We transformed to a new web server with an entirely updated software program pile, consisting of apache 2.4 and also php 5.6.9. We have a web page in Simplified Chinese. On our old web server (apache 2.2, php 5.3.5), the web pages simply provided effectively. The website remains in UTF - 8 in the majority of means, other than that the web page concerned has the adhering to tags:

<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030" />

From the new website, the web page does not provide effectively unless the internet browser encoding is transformed for that web page. For Chrome, Firefox and also IE, the setup adjustment is comparable: View > Encoding > gb18030 (on Firefox, Chinese, Simplified).

What is creating the new arrangement to need this override in the internet browser, which was never ever formerly called for?

2
2022-07-25 20:39:07
Source Share
Answers: 1

We tried lots of things but finally got something to work. We have to send a header before sending any other output. Thus the cause proposed by Simon Hayter is correct, and our solution implements the correction.

Here is what the first two lines or our code looks like:

<?php
header('Content-Type:text/html;charset=gb18030');

We believe the root cause is that the default action for apache changed between version 2.2 and 2.4, which was part of our stack upgrade. Apparently version 2.4 sets the default charset to UTF-8 in the header, and nothing we tried (of many apache configuration options) was able to change that. No matter what we tried, 2.4 sent the following header:

Content-Type: text/html; charset=UTF-8

On the other hand, our apache 2.2 was sending the following header:

Content-Type: text/html

There were no other significant difference in the server output (which was obtained via curl).

As I said, we could not get the apache 2.4 to not send the charset=UTF-8, even with using AddDefaultCharset, etc.

So the workaround is to have php send a header as shown above.

I am attaching an image of part of a diff, showing what I am talking about.The difference marked "17" shows the difference.

1
2022-07-25 21:22:34
Source