Forum Moderators: phranque

Message Too Old, No Replies

charset=UTF-8 being added to Content-Type header

just for one or two files - can't figure out what's causing it

         

q_1983

5:51 pm on Jul 12, 2010 (gmt 0)

10+ Year Member



Hi,

I hope this is the right place to post...

I've been trying to fix some broken characters on my site. I've tracked the problem to the default encoding. I'm passing a meta tag as follows in the standard header in php for all my pages:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


I can verify that the browser is finding this and reports the meta tag correctly.

However on a couple of my pages, the http header is being changed from the default:

Content-Type: text/html


to

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


I don't know where this is coming from! All the pages are generated the same way.

I've tried putting a php header directive into the two problem files before any text is output. The php manual says that the header entries will replaced if they already exist:

header("Content-Type:text/html; charset=ISO-8859-1");


But nothing happens. No replacement. I made sure the command was correct. I tried:

header("Crap:text/html; charset=ISO-8859-1");


I checked in the browser and the new Crap header entry was there.

The PHP Manual says you can opt to add rather than replace, if you pass false as the optional second argument. So I tried this expecting to see the problem UTF line followed by my new line:

header("Content-Type:text/html; charset=ISO-8859-1", 0);


But still, only the UTF-8 line makes the header entries.

I tried putting an entry into the .htaccess file:

<Files "problemFile.php">
ForceType 'text/html; charset=ISO-8859-1'
</Files>


but that just stuffed everything up. I don't think it got parsed as php then.

I tried creating a new file with a different name, and pasting the contents of the old file in. Same result. Which suggests that its somewhere in the contents of the file! But there is nothing that isn't in all the other files on my site. And they work don't have this problem.

I'm at my wits end!

Any help greatly appreciated.

PS - My site is one of a few on a Plesk server. I have root access to it.

q_1983

6:26 pm on Jul 12, 2010 (gmt 0)

10+ Year Member



It's always the way!

You struggle for hours, then in desperation you post your question hoping someone can help. Then you solve your problem.

It turned out I was including an RSS feed module on those pages and it was setting the encoding type to UTF-8. It was included almost at the bottom of the code, so I missed it.

Seriously difficult bug to fix!

jdMorgan

1:30 am on Jul 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I'm glad you found it... I looked at some mobile Web pages that I intentionally serve with the "charset=UTF-8" in the header, but in every case I had to 'force' that to happen -- It didn't happen by itself.

Then while trying to figure out how to say that without sounding rude, I saw that you'd identified the problem... Good!

Jim