Jump to content

UTF-8 header send already


Logical1

Recommended Posts

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

Link to comment
Share on other sites

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++

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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



Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

شروع عضویت حدس بزنید راهنما حدسها و نتیجه ها نظر خواهی و تماس اخبار ورزشی جالب خروج از سیستم مسابقات تیمها

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.