KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: The importance of consistent encoding when Web serving.
PRODUCT: 4D | VERSION: 13.1 | PLATFORM: Mac & Win
Published On: October 19, 2012

Web serving with any system involves at least three ways to manage text encoding:

  • HTTP requests and responses may contain encoding information via the "Content-Type" HTTP header, for example Content-Type: text/html; charset=utf-8

  • HTML content sent to the browser can contain encoding information embedded in the page via a "meta" tag, for example <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>. Similarly XHTML content may contain the encoding in the XML declaration (usually the first line of the file) for example <?xml version="1.0" encoding="UTF-8"?>.

  • Requests sent to the server may also specify an encoding, for example via the "accept-charset" attribute of a "form" element: <form action="form_action" accept-charset="ISO-8859-1">.

4D also provides a global encoding setting called "Standard Set" in the Database Settings as explained this this Tech Tip. IMPORTANT NOTE: this value is only used for dynamic and semi-dynamic responses.

The important thing to understand is all of these should be set to the same encoding!


If 4D has a Standard Set of "UTF-8", don't embed a meta tag or xml declaration in a dynamic response that uses "ISO-8859-1". Don't serve static pages in one encoding and dynamic responses in another.

If the encodings are mismatched, it is up to the browser to choose which encoding to use; it is no longer in the developer's control. Different browsers may have different interpretations. And worse yet data posted from the browser may arrive in an unexpected encoding!

Incidentally to fix that last issue, use "accept-charset" attribute of a "form" element:

http://www.w3schools.com/tags/att_form_accept_charset.asp

See Also: