We changed to a new server with a completely upgraded software stack, including apache 2.4 and php 5.6.9. We have a page in Simplified Chinese. On our old server (apache 2.2, php 5.3.5), the pages just rendered properly. The site is in UTF-8 in most ways, except that the page in question has the following tags:

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

From the new site, the page does not render properly unless the browser encoding is changed for that page. For Chrome, Firefox and IE, the setting change is similar: View > Encoding > gb18030 (on Firefox, Chinese, Simplified).

What is causing the new setup to require this override in the browser, which was never previously required?


1 Answer 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:


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.

diff showing the different apache headers


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.