1
nachenko
Server delivering files in wrong charset
  • 2007/10/5 10:04

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


Man, when a server wants to piss off...

Some of you know that I do stuff for a University, and every time I have to cope with their servers is like a pain in the ass.

This time the problem is that the server is ignoring this:



Pges are ISO-8859-1 encoded, as usual in spanish XOOPS installations, but it delivers the pages in UTF-8 instead. In Firefox, you go into "page properties", and it's very clear: meta charset blablabla ISO-8859-1, page encoding UTF-8. Spanish special characters totally [the f... word here] up! Force the browser to use ISO-8859-1 encoding instead of autodetect, and everything looks fine.

What's wrong, why can't it simply autodetect the charset from the META field as most sites do?

I'm sure it's a server configuration, but we can't touch it, we need a solution that can be used in a .htaccess file.

I've tried this:

AddDefaultCharset ISO-8859-1

in a .htaccess file, no luck.

Suggestions welcome, thank you.

2
JMorris
Re: Server delivering files in wrong charset
  • 2007/10/5 11:16

  • JMorris

  • XOOPS is my life!

  • Posts: 2722

  • Since: 2004/4/11


If you've put AddDefaultCharset ISO-8859-1 in a .htaccess file in the web root and the server is ignoring the directive, it is possible that the server admin has set AddDefaultCharset off. A lot of Apache configs I've seen default to UTF-8, so having AddDefaultCharset off might produce this symptom. If you set AddDefaultCharset On a default charset of iso-8859-1 is used.

Try this in your .htaccess file...

AddDefaultCharset On


HTH

ref: AddDefaultCharset
Insanity can be defined as "doing the same thing over and over and expecting different results."

Stupidity is not a crime. Therefore, you are free to go.

3
nachenko
Re: Server delivering files in wrong charset
  • 2007/10/8 9:12

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


Thanks, JMorris, I'll try today.

4
nachenko
Re: Server delivering files in wrong charset
  • 2007/10/8 17:23

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


Still no luck.

Server keeps doing exactly the same.

Moreover, i've converted ALL FILES and database to utf8. Opened in Dreamweaver, saved in UTF-8. Database was exported, SQL file converted to UTF-8, reviewed the file so "collation" and "character" is always utf8, then created a new UTF-8 database using the previously exported file, loaded as UTF-8.

Using PHPmyAdmin shows special characters correctly.

But then, I open the page in local using XAMPP, everything is UTF-8, the output received by the browser, the character set specified is UTF-8... but the database output looks scrambled, special characters are all wrong...

WTF!!!

The db is UTF-8, the php files are all them utf-8, the output is UTF-8, but I change the charset in the browser to Latin1 and the DB output in the browser looks right!!!

What's wrong?

5
gtop00
Re: Server delivering files in wrong charset
  • 2007/10/8 17:36

  • gtop00

  • Friend of XOOPS

  • Posts: 498

  • Since: 2004/11/13


Hi nachenko,

There are two tutorials at http://www.xoopsgreece.gr that deal with this phenomenon...

1. Create a UTF-8 database
2. Convertinga Database to UTF-8

Try to follow with the help of the english texts (inside the Greek...) and the screenshots.

If you need to translate some points let me know.

6
nachenko
Re: Server delivering files in wrong charset
  • 2007/10/8 17:42

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


Hi!

I found something about this:

mysql_query("SET NAMES 'utf8'", ...

What is that? It says something like PHP defaults to latin1 on MySQL queries.

Quote:
I found the cause of my problem - after doing many hours of reading - to be a default PHP setting:

A PHP MySQL connection (...) defaults to a latin1 connection, so, your first query after connection should be:

mysql_query("SET NAMES 'utf8'");


http://www.adviesenzo.nl/examples/php_mysql_charset_fix/

7
gtop00
Re: Server delivering files in wrong charset
  • 2007/10/8 18:08

  • gtop00

  • Friend of XOOPS

  • Posts: 498

  • Since: 2004/11/13


Very interesting page. I did know that...

And Yes, you have to convert the "connect to the database" in file "class/database/mysqldatabase.php" as follows (around the line 48):

Quote:
* connection to a MySQL database
*
* @abstract
*
* @author Kazumi Ono
* @copyright copyright (c) 2000-2003 XOOPS.org
*
* @package kernel
* @subpackage database
*/
class XoopsMySQLDatabase extends XoopsDatabase
{
/**
* Database connection
* @var resource
*/
var $conn;

/**
* connect to the database
*
* @param bool $selectdb select the database now?
* @return bool successful?
*/
function connect($selectdb = true)
{
extension_loaded('mysql') or trigger_error('mysql extension not loaded', E_USER_ERROR);
if (XOOPS_DB_PCONNECT == 1) {
$this->conn = @mysql_pconnect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
} else {
$this->conn = @mysql_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
}

if (!$this->conn) {
$this->logger->addQuery('', $this->error(), $this->errno());
return false;
}

if($selectdb != false){
if (!mysql_select_db(XOOPS_DB_NAME)) {
$this->logger->addQuery('', $this->error(), $this->errno());
return false;
}
}
mysql_query('SET character_set_results="utf8"');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES 'utf8'");
return true;

}

Login

Who's Online

115 user(s) are online (67 user(s) are browsing Support Forums)


Members: 0


Guests: 115


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits