Logical1 Posted May 14, 2009 Share Posted May 14, 2009 I noticed that when a php file is saved as UTF-8 (I have to use non-english fonts and hence the UTF-8 saving) I keep on getting header send already errors when I try to regiter a session or cookies. The exact same php file saved as ascii does not casue any problem so it must not be the code but being UTF-8.Can anyone explain why and how to det around this issue and register sessions or cookies in a UTF-8 file? Thanks in advance L1 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2009 Share Posted May 14, 2009 The problem is the BOM (Byte Order Mark) characters that the editor places at the start of the file. They are not needed when the web page is published and you should save your files as UTF-8 but without the BOM. If your editor does not offer that option, use an programming editor like notepad++ Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 14, 2009 Author Share Posted May 14, 2009 Thank you for your answer. I use Notepad and I earched the help there is no option for BOM I will download the notepad++ Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 14, 2009 Share Posted May 14, 2009 I use Notepad Hopefully you will move to Notepad++ once you download it... Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 16, 2009 Author Share Posted May 16, 2009 I downloaded the notepad++ opened the same php file and saved it with the option UTF-8 without BOM. Problem got bigger now! Not only the fonts att turned into Øدسها Ùˆ نتیجه ها I am still getting header already send message!! What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 16, 2009 Share Posted May 16, 2009 Dis you use Format > Convert to UTF 8 without BOM? Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 16, 2009 Author Share Posted May 16, 2009 yes.can omebody else try entering fornts of non english type (say arabic or japanese or similar) and see if you can remove the bom? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 16, 2009 Share Posted May 16, 2009 I'm using it all the time with Polish fonts. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2009 Share Posted May 16, 2009 For the version of your file that outputs the correct language characters, what is the actual header() error message? If the message refers to output on line 1 of the file, then the problem is likely the BOM. If the message refers to output at a line greater than line 1 of the file, the problem is something that you are outputting. Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 16, 2009 Author Share Posted May 16, 2009 I have no doubt that there is a way and I am doing womething wrong. This I copy directly from the browser : اصلی شروع عضویت Øدس بزنید راهنما Øدسها Ùˆ نتیجه ها نظر خواهی Ùˆ تماس اخبار ورزشی جالب خروج از سیست٠This is what I get. The font is supposed to be Persian and show: شروع عضویت حدس بزنید راهنما حدسها و نتیجه ها نظر خواهی و تماس اخبار ورزشی جالب خروج از سیستم مسابقات تیمها The option in format is Convert to UTF-8 without BOM an then I save it (as 123.php with default option All types *.*) Would you please write the setting you have? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 16, 2009 Author Share Posted May 16, 2009 PFMaBiSmAd now with Notepad ++ I can register the session but problem is that the Perian fonts show as funny characters. If I save the file as UTF-8 without BOM then I can not register session and get header already sent error message. Exact error message are: in /----------------/login.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /----------------/login.php:1) in /mnt/w0900/d34/s39/b02eb908/www/hadsi.com/login.php on line 17 Warning: Cannot modify header information - headers already sent by (output started at /----------------/login.php:1) in /----------------/login.php on line 19 Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 16, 2009 Share Posted May 16, 2009 Here's what I did 1. Open new document in notepad++ 2. Select Format > Encode in UTF-8 (with BOM) 3. Paste this code <?php session_start(); ?> شروع عضویت حدس بزنید راهنما حدسها و نتیجه ها نظر خواهی و تماس اخبار ورزشی جالب خروج از سیستم مسابقات تیمها and save the file 4. Open this in browser - the header error appears 5. Get back to Notepad++ - select Format > Convert to UTF-8 without BOM and save the file 6. Get back to browser, refresh. The error is gone, and the Persian characters appear correctly. Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 16, 2009 Author Share Posted May 16, 2009 Thank you very much for taking the time to help. I did exctly what you suggested step by step. I loaded the file both time to my web server and both time I get: شروع عضویت Øدس بزنید راهنما Øدسها Ùˆ نتیجه ها نظر خواهی Ùˆ تماس اخبار ورزشی جالب خروج از سیستم مسابقات تیمها This is wierd if I don't include BOM fonts wont get recognized. I can not figure out how you do the exact same thing and get a different result unless it has something to do with the web server. You save is as what? with which option? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 16, 2009 Share Posted May 16, 2009 As a php file. A thought... maybe your browser does not recognize it as UTF? Try switching encoding in browser. Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 16, 2009 Author Share Posted May 16, 2009 I use the same browser for all other pages which are utf-8. when you save what do you select as type? text? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 16, 2009 Share Posted May 16, 2009 Thing is: when you remove BOM, the browser might not recognize content as UTF8. You might need to send proper header first <?php header("Content-Type: text/html; charset=utf-8"); or use html meta tag <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> to tell the browser to switch to utf-8 I switched encoding in my browser from utf-8 to Windows-1520 and got exactly same output as you did. Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 17, 2009 Author Share Posted May 17, 2009 It is back to the first problem now (header sent): if I add this to the code which becomes: <?php session_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <body> شروع عضویت حدس بزنید راهنما حدسها و نتیجه ها نظر خواهی و تماس اخبار ورزشی جالب خروج از سیستم مسابقات تیمها </html> I get the following error: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /----------/test.php:1) in /mnt/w0900/d34/s39/b02eb908/www/hadsi.com/test.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /--------------------/test.php:1) in /--------------/test.php on line 2 شروع عضویت حدس بزنید راهنما حدسها و نتیجه ها نظر خواهی و تماس اخبار ورزشی جالب خروج از سیستم مسابقات تیمها Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 17, 2009 Share Posted May 17, 2009 You clearly are doing something wrong. See attached file: [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Logical1 Posted May 17, 2009 Author Share Posted May 17, 2009 I loaded the file to my server and works beautifully. I opened it in Notepad++ and just made one space and saved it and oaded again and it works fine. So obviouly there is something wrong with the way I am saving them. I will try to figure it out. Mchl thank you very much for your generous help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.