Why is UTF-8 encoding lost after POST request?
<p>I have a simple jquery ajax post cal to send some data to a server. The data contains characters in UTF-8.</p>

<p>Here is the code:</p>

<pre><code>var data = {
    name: "Ländertrends"
}

var data_string = JSON.stringify(data);
console.log(data_string); //encoding still looks good here

$.ajax({
    type: "POST",
    url: "includes/savedashboard.php",
    data: { saveDashboard: data_string, dashboardname: name, conf: conf },
    contentType: "application/x-www-form-urlencoded; charset=utf-8",        

    success: function(result) {

        console.log(result);

    }
}); 
</code></pre>

<p>includes/savedashboard.php looks like this:</p>

<pre><code>&lt;?php
header('Content-Type: text/html; charset=UTF-8');
var_dump($_POST['saveDashboard']);
?&gt;
</code></pre>

<p>On my development server (Ubuntu 14.04, Apache2, PHP 5.5.9), the output is fine and looks like you would expect:</p>

<blockquote>
  <p>string(24) "{"name":"Ländertrends"}"</p>
</blockquote>

<p>However, on a second server (CentOS 6.8, Cpanel, Apache2, PHP 5.4.45), the encoding is messed up:</p>

<blockquote>
  <p>string(25) "{"name":"L���ndertrends"}"</p>
</blockquote>

<p>I can see the content type of the request comes back as UTF-8.</p>

<p>If I use mb_detect_encoding() it says the string is in EUC-JP.</p>

<p>My guess is that some system setting is making the difference, but which one?</p>

<p>I have already set the content type, also added <code>AddDefaultCharset UTF-8</code> to a <code>.htaccess</code> file, and added <code>charset="utf-8"</code> to my script tags, but it doesn't seem to make a difference.</p>

<p>Can anyone point me in the right direction?</p>

<p>By the way, I can work around the problem by converting the string back to UTF-8, but I would like to know why this is happening on one server and not the other.</p>