Click to See Complete Forum and Search --> : encoding problem


Guezt
01-25-2010, 04:20 AM
i've got a site with the following

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

when i view the site on my localhost apache server all is well, but when i move it to my webspace on a different apache server (the settings of which i have no control over) i get trouble

safari, ie and chrome show the page fine, but firefox and opera get the encoding wrong (both have messed up umlauts and firefox shows the utf-8 bom as  in the upper left corner of the page)
in firefox' page info it says Encoding: ISO-8859-1, altho' it also recognizes the meta/content type as text/html; charset=UTF-8

i've set the actual encoding of the file(s) in notepad++ to utf-8

any idea how i could force the client browser to treat the site as utf-8?


*edit* putting the following at the beginning of the file seems to have fixed the problem:
<?php header("Content-type: text/html; charset=UTF-8"); ?>
still, i'd like to know why the problem existed in the first place?

Charles
01-25-2010, 06:00 AM
Because that line <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> is really meaningless in HTTP. What matters is the behind the scene communication between the server and the browser, the response headers. The line <?php header("Content-type: text/html; charset=UTF-8"); ?> sets those response headers, or it sets the one we need. On some servers, and aparently not yours, the http-equiv meta elements are another method of adjusting those response headers.

When you are off line there are no response headers so the browser has to fall back and use other ways to figure out the encoding.

Guezt
01-25-2010, 06:11 AM
i see

so when the encoding isn't explicitly set with, for example php, does the server send a null charset or is it some default from apache settings?

Fang
01-25-2010, 07:40 AM
Whatever is set in httpd.conf or .htaccess files on the server.