My database communicates incorrectly with my page coded in php. First just some of the special characters displayed incorrectly, but when I applied mysqli_set_charset for my connection and default latin1 was overridden to correct utf8, my problem seemed just to change, but it wasn't solved: whenever I sent a text to database, it ended just before the first non-ASCII character. I searched more and found out that to state the encoding in a meta tag is not enough, that I must use headers. At first, I included header('Content-Type: text/html; charset=utf-8');
statement to the top of some of my pages. Not the texts taken from or inserted into database are correct, but on the rest of the page all special characters display like this: �
Also, having the header function called in every file is not very practical. I'm a beginner with headers, so I don't know how to apply this settings globally. I know .htaccess file can be used for this and my host claims to support it, so I started experimenting with it. I tried all the options suggested here, but nothing changed.
I guess both problems have the same cause: the files I get from the server are in a different charset (I don't have a proof, but the server seem to prefer latin). So how to tell the server I want them in utf8?
Settings as read by apache_request_headers (the important fields):
ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
ACCEPT-LANGUAGE: cs,en-us;q=0.7,en;q=0.3
ACCEPT-ENCODING: gzip, deflate
Only Mozilla Web-Sniffer sees some informations about charsets (and it varies in the languages):
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
Accept-Language: de,en;q=0.7,en-us;q=0.3
Here is my .htaccess file:
<FilesMatch ".(html|htm|js|css|php)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
AddCharset UTF-8 .php
</ifModule>
</FilesMatch>
Instead of "AddCharset UTF-8 .php" I used alternatives too, but nothing worked. But I'm a beginner, so there might be some mistake.
If I need something completely different, please guide me. Someone suggested XML might help, but here I'm lost even more than with the HTTP headers.
EDIT: I can't see my answer in the linked question. Yes, it guided me to php.ini, but I got only more subquestions, not answers (anything listed there don't work for me).
First, the php.ini file for my server is stored in the part of server I can't access. So I tried to create my own php.ini file in hope it will work. It consists of chunks of code I found elsewhere (I can't confess I understand it):
default_charset = "utf-8";
AddDefaultCharset UTF-8;
[iconv]
iconv.input_encoding = utf-8;
iconv.internal_encoding = utf-8;
iconv.output_encoding = utf-8;
exif.encode_unicode = utf-8;
Again, no joy here. What's wrong?