Something i never seen before happened on my hosting server. a couple of PHP files containing CHINESE language that i have saved in UTF-8 coding and to which i also added the usual <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/> just keeps on dropping the UTF-8 coding at random intervals on this particular hosting server (but not on my other server). My PHP files start with PHP Session as a standalone PHP commando for the contact form. The hoster suggested i use the equivalent PHP header for the UTF-8 (instead of the HTTP-EQUIV) and i played around with this a bit - to no useful result. So i hope i find someone how could just write it out as usable copy and paste bit of code that goes on top of my .php files. It should simply contain the normal Session Start plus the header UTF-8 and that's all. I hope i can then find out whether i wrote my code bit wrong or the issue is definitively server side. Thanks for that bit of PHP knowledge handed down
Thanks, i knew that much, but i have to combine sessions start AND header. Currently i use <?php session_start(); header('Content-Type: text/html; charset=utf-8'); the trouble is that this works on 1 of my hosting servers - but i get error messages on another, different hosting server! This is why i wanted to double check with someone who knows PHP well enough to see if i have anything wrong - i personally suspect however the problem is with the PHP modules of that server where i get the error messages????? Thanks for fool proof clearance for me.
There isn't anything wrong with your current code. It would however help if you could post the errror you get.
I have just changed things on the file in question back to exactly the code as i posted it in my last post and uploaded it that way for just 1 minute to copy and paste the error message. This is what it read index.php is the main page, it has indeed also a UTF-8 HEAD as in this index.php file can not be without UTF-8 as it is in CHINESE (the file in question, cn7g.php, is opening inside index.php and displays a contact form. See http://proftech.cn/ I can also not run index.php with <?php session_start(); ?> <html> <head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/> <meta http-equiv="Content-Language" content="cn"> and have no UTF-8 declaration on cn7g.php, i tested that already. Both files need to be in UTF-8 as both contain Chinese, the contact form also to take on Chinese input to be delivered as chinese to the email. As mentioned, on the other server i did not get an error message, on this server i can only run both files with the HTML Meta charset <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/> in both files, that causes no error messages and displays the foreign language right - until some fine day the UTF-8 encoding simply disapears (while no one is doing anything on the files on this strange server) - and of course the entire chinese is then nothing but "?" question marks! tests with <?php session_start(); header('Content-Type: text/html; charset=utf-8'); on at least the index.php file (where this worked) did not prevent the "dropping" of the UTF-8 encoding after an irregular amount of time either. Question: Is there anything in the coding i as a web designer can change or correct or is this - as i assume - a problem at the hosts PHP modules?
First, why don't you serve ALL your pages with utf8? Second, you get the error due to not running ob_start Before either of the lines, add ob_start(); It let's all the info on the page be gathered before outputting anything, including headers