Page 1 of 1

An umlaut problem

Posted: Tue Nov 19, 2013 6:39 pm
by Griffel
Script URL: http://mg.hasenlauf.de/t/gbook/gbook.php
Version of script: 1.7
Hosting company: unknown, it's a rented system by a friend of me, I assume it's a dedicated server
URL of phpinfo.php: http://mg.hasenlauf.de/t/gbook/phpinfo.php
URL of session_test.php: http://mg.hasenlauf.de/t/gbook/session_test.php
What terms did you try when SEARCHING for a solution: umlaut, coding, iso-8859-1, utf-8

Dear friends of GBook,

Regading my test installation (URL see above), function "Sign guestbook": Every time, when I use an "umlaut" character (e. g. "André", characters like äÄöÖüÜßéÉèÈêÊóÓòÒâ ...) in the entry field "Your name:" or "Comments:" and I press "SUBMIT MY COMMENT", the field gets cleared and an error message occures ("Please enter your name"/"Please enter your comments").
It's curious, the Demo GBook Guestbook doesn't have this problem. So my question is, what's the difference between my test installation and the demo guestbook?

I asssumed, the problem lies in the page coding. Therefore I tried different settings in language.inc.php. Instead of the default $lang['enc']='windows-1250'; I tried $lang['enc']='iso-8859-15'; and $lang['enc']='utf-8';, but this didn't solve the problem.

Does anyone has an idea what causes this problem?

Kind regards,

Griffel

Re: An umlaut problem

Posted: Tue Nov 19, 2013 6:56 pm
by Klemen
Hi,

This happens because of a very annoying change PHP team did in PHP a while ago and has been causing endless headaches to international developers since.

Anyway, please try this:

1. Use

Code: Select all

$lang['enc']='utf-8';
2. In gbook.php change this code

Code: Select all

$in = htmlspecialchars($in);
to this

Code: Select all

$in = htmlspecialchars($in, ENT_COMPAT | ENT_SUBSTITUTE | ENT_XHTML, 'UTF-8');

Re: An umlaut problem

Posted: Tue Nov 19, 2013 7:28 pm
by Griffel
Thanks, Klemen for the quick reply.

Now input of umlaut chars works, fine!
But, look at the output, the umlaut signs are not right displayed: http://mg.hasenlauf.de/t/gbook/gbook.php
I checked it with different browsers, Chrome, Firefox, IE and Safari. No matter what browser, the problem occures at all browsers.

Kind regards,

Griffel

Re: An umlaut problem

Posted: Tue Nov 19, 2013 7:39 pm
by Klemen
Hmm, does it make any difference if you use uppercase UTF-8 in language file?

Code: Select all

$lang['enc']='UTF-8';
(make the change and before testing close all browser windows)

Re: An umlaut problem

Posted: Tue Nov 19, 2013 7:50 pm
by Griffel
No, it makes no difference. Again, I checked it with the 4 browsers (closing all windows, restart).
Thanks again for your help!

Regards,

Griffel

Re: An umlaut problem

Posted: Tue Nov 19, 2013 8:17 pm
by Griffel
BTW, the problem occures at the notification e-mails too.

Suject: Someone has just signed your guestbook
Hello!

Someone has just signed your guestbook!

Name: G�nter
From:
E-mail:
Website:
Message (without smileys):
Umlaut-Test. �������

Visit the below URL to view your guestbook:
http://mg.hasenlauf.de/t/gbook/gbook.php

End of message

Griffel

Re: An umlaut problem

Posted: Wed Nov 20, 2013 12:13 pm
by Klemen
The problem seems to be that the browser isn't detecting encoding as UTF-8, but as Western European.

If I force the page to be displayed in UTF-8 and submit an entry it works fine.

What I would try is:

1. Upload an empty "entries.txt" file

2. Open these files in a powerful text editor, such as the free Notepad++:
gbook.php
language.inc.php
settings.php

3. Save all these three files in UTF-8 encoding *without* BOM (byte order mark)

4. Upload and test again.

Re: An umlaut problem

Posted: Wed Nov 20, 2013 2:32 pm
by Griffel
Dear Klemen,

I did so, but it doesn't help.
In notepad++ I converted the files to UTF-8 without BOM.

What do you think about this try:
Include <meta charset="UTF-8"> in the <head>-section of the web pages.
But I don't know where to insert this in which file.

Regards,

Griffel

Re: An umlaut problem

Posted: Wed Nov 20, 2013 2:44 pm
by Klemen
That won't help, the two tags are compatible.


I think I found the problem - your server is sending this header inside the "t" folder:

Code: Select all

Content-Type: 	text/html; charset=iso-8859-15
This makes the browser select iso-8859-15 and disregard what the HTML tells it.

You will need to verify (with your host) why this header is being forced.

You can also try adding this to the top of your gbook.php (just after <?php ) and see if it helps, not sure if the server-set header will prevail or not:

Code: Select all

header('Content-Type: text/html; charset=utf-8');

Re: An umlaut problem

Posted: Wed Nov 20, 2013 3:04 pm
by Griffel
Klemen wrote:I think I found the problem - your server is sending this header inside the "t" folder:

Code: Select all

Content-Type: 	text/html; charset=iso-8859-15
Yers, it can be seen by phpinfo.php, section "Core", value of "default_charset".
Klemen wrote:You will need to verify (with your host) why this header is being forced.
I will do so.
Klemen wrote:You can also try adding this to the top of your gbook.php (just after <?php ) and see if it helps, not sure if the server-set header will prevail or not:

Code: Select all

header('Content-Type: text/html; charset=utf-8');
This works!
Even the notification email is now right formatted.

Thanks a lot for your support!

Kind Regards,

Griffel

One more small question

Posted: Wed Nov 20, 2013 3:22 pm
by Griffel
One more small question: Now I'm going to fix some errors in "deutsch.inc.php". There are umlauts represented like "&#228;" for "ä".
Is there a trick in Notepad++ to let the editor format the umlauts in this way?

Re: An umlaut problem

Posted: Wed Nov 20, 2013 3:23 pm
by Klemen
Not that I know, you will probably need to rely on the old "Search and replace"...

Re: An umlaut problem

Posted: Wed Nov 20, 2013 3:32 pm
by Griffel
Thanks! I'll do so.